setMyCommands
设置 Bot 的命令列表。用户在输入框中输入 / 时会看到这些命令。
请求
POST /:token/setmycommands
参数
| 参数 | 类型 | 必填 | 描述 |
|---|---|---|---|
| commands | BotCommand[] | 是 | Bot 命令对象数组,每个对象包含 command 和 description 字段 |
| scope | BotCommandScope | 否 | 命令的作用范围,默认为所有聊天 |
| language_code | String | 否 | 语言代码(IETF),用于指定特定语言的命令列表 |
BotCommand 对象
| 字段 | 类型 | 描述 |
|---|---|---|
| command | String | 命令文本,1-32 个字符,仅包含小写字母、数字和下划线 |
| description | String | 命令描述,1-256 个字符 |
响应
成功时返回 Boolean 值 true。
json
{
"ok": true,
"result": true
}请求示例
json
{
"commands": [
{
"command": "start",
"description": "启动机器人"
},
{
"command": "help",
"description": "获取帮助信息"
},
{
"command": "settings",
"description": "修改设置"
}
]
}错误码
| 错误码 | 描述 |
|---|---|
| 400 | 请求参数错误,如 commands 格式无效或 command 包含非法字符 |
| 401 | Token 无效或已过期 |
| 500 | 服务器内部错误 |
