Reputation: 2327
Is it possible to create/delete a new command for Telegram Bot using python? I know that BotFather can create commands using /setcommands
but I am trying to see if I can automate creating a list of commands using Python. I am using pyTelegramBotAPI
to interact with the bot.
For example, can I batch process the following command creation without typing them in the Telegram Mobile or Desktop App?
command1 - Description for command 1
command2 - Description for command 2
command3 - Description for command 3
I would like to help the user with available commands and as soon as they type /
I'd like Telegram to automatically show them /command1
, /command2
, /command3
.
I tried the following but it does not seem to be working. None of the commands will show up after typing /
in the app.
import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands('command1')
tb.set_my_commands('command2')
tb.set_my_commands('command3')
Lastly, does Telegram allow to delete a command using Python?
Upvotes: 0
Views: 4040
Reputation: 106
Everything is pretty easy, although there is no guide for it.
import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands([
telebot.types.BotCommand("/start", "main menu"),
telebot.types.BotCommand("/help", "print usage")
])
So I suggest there is no need to delete commands, as they overwrite each time set_my_commands run.
Upvotes: 5