setMySettings
更改机器人设置:内联模式、隐私、群组、话题、回调查询模式 (Bot API 10.5)。
返回值: 调用成功时返回 True。
参数
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
supports_inline_queries | Boolean | 可选 | 启用 (true) 或禁用 (false) 内联模式 |
inline_query_placeholder | String | 可选 | 输入框中显示的内联查询占位文本(空字符串 = default) |
needs_inline_query_location | Boolean | 可选 | 每次内联查询时请求用户位置 |
inline_feedback_share_denominator | Integer | 可选 | 接收所选内联结果的比例:N 个中 1 个(1、10、100、1000;0 = 不接收) |
can_join_groups | Boolean | 可选 | 允许将机器人添加到群组 |
can_read_all_group_messages | Boolean | 可选 | true = 关闭隐私模式(读取群组所有消息) |
can_connect_to_business | Boolean | 可选 | 允许将机器人连接到商业账户 |
can_manage_bots | Boolean | 可选 | 允许机器人创建受管机器人 |
supports_guest_queries | Boolean | 可选 | 允许来自机器人未加入的聊天的访客查询 |
supports_join_request_queries | Boolean | 可选 | 允许指定机器人处理加入请求 |
has_topics_enabled | Boolean | 可选 | 在与机器人的私聊中启用论坛话题模式 |
allows_users_to_create_topics | Boolean | 可选 | 允许用户在私聊中创建和删除话题 |
has_topic_sidebar | Boolean | 可选 | 在侧边栏中显示私聊话题 (Bot API 10.5) |
can_communicate_with_bots | Boolean | 可选 | 允许机器人与其他机器人通信 |
callback_query_mode | String | 可选 | 回调查询模式:default、auto 或 inline(以 inline_message_id 代替 message) |
请求示例
curl
curl -s -X POST "https://api.telegram.org/bot$TOKEN/setMySettings" \
-H "Content-Type: application/json" \
-d '{
"supports_inline_queries": true,
"can_read_all_group_messages": false,
"callback_query_mode": "auto"
}'
Python
import requests
TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
f"https://api.telegram.org/bot{TOKEN}/setMySettings",
json={
"supports_inline_queries": True,
"can_read_all_group_messages": False,
"callback_query_mode": "auto"
},
timeout=30,
)
print(resp.json())
JavaScript
const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setMySettings`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({
"supports_inline_queries": true,
"can_read_all_group_messages": false,
"callback_query_mode": "auto"
}),
});
console.log(await res.json());
分步教程: Telegram 机器人教程:从零创建 Telegram 机器人并发送第一条消息
相关方法
getMe返回机器人信息(自 Bot API 10.5 起为 BotFullInfo)。getMyCommands返回机器人当前的命令列表。setMyCommands设置机器人的命令列表。deleteMyCommands删除机器人命令。getMyName返回机器人的名称。setMyName设置机器人的名称。getMyDescription返回机器人的描述。setMyDescription设置机器人的描述。getMyShortDescription返回机器人的简短描述。setMyShortDescription设置机器人的简短描述。setMyProfilePhoto设置机器人的头像。removeMyProfilePhoto移除机器人的头像。