Telegram Bot API
🌐 Português

setMyCommands

Categoria: Info do bot · Bot API 10.3 · Documentação oficial

Define a lista de comandos do bot.

Retorno: Em caso de sucesso, retorna True.

Parâmetros

ParâmetroTipoObrigatórioDescrição
commandsArray of BotCommandSimArray JSON de BotCommand [{"command":"start","description":"Begin"}]
scopeBotCommandScopeOpcionalObjeto JSON BotCommandScope
language_codeStringOpcionalCódigo de idioma

As descrições dos parâmetros são resumos concisos; consulte a documentação oficial para ver o texto completo.

Exemplo de requisição

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());

Guia passo a passo: Como criar um bot no Telegram grátis: do BotFather à primeira mensagem