Telegram Bot API
🌐 Русский

setMyCommands

Категория: Информация · Bot API 10.3 · Официальная документация

Устанавливает список команд бота.

Возвращает: При успехе возвращает True.

Параметры

ПараметрТипОбязательныйОписание
commandsArray of BotCommandДаJSON массив BotCommand [{"command":"start","description":"Begin"}]
scopeBotCommandScopeНетJSON объект BotCommandScope
language_codeStringНетКод языка

Описания параметров даны кратко; полный текст — в официальной документации (на английском).

Пример запроса

curl

curl -s -X POST "https://api.telegram.org/bot$TOKEN/setMyCommands" \
  -H "Content-Type: application/json" \
  -d '{"commands":[{"command":"start","description":"Start the bot"}]}'

Python

import requests

TOKEN = "123456789:AAEexampleTokenReplaceWithYours"
resp = requests.post(
    f"https://api.telegram.org/bot{TOKEN}/setMyCommands",
    json={
        "commands": [
            {
                "command": "start",
                "description": "Start the bot"
            }
        ]
    },
    timeout=30,
)
print(resp.json())

JavaScript

const TOKEN = "123456789:AAEexampleTokenReplaceWithYours";
const res = await fetch(`https://api.telegram.org/bot${TOKEN}/setMyCommands`, {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
    "commands": [
      {
        "command": "start",
        "description": "Start the bot"
      }
    ]
  }),
});
console.log(await res.json());

Пошаговое руководство: Как создать бота в Телеграм: от @BotFather до первого сообщения