Telegram Bot API

setMyCommands

Категорія: Інформація · Bot API 10.5 · Офіційна документація

Встановлює список команд бота.

Повертає: У разі успіху повертає True.

Параметри

ПараметрТипОбов’язковийОпис
commandsArray of BotCommandТакJSON-масив BotCommand [{"command":"start","description":"Почати"}]
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 до першого повідомлення