Create/Delete Telegram 机器人命令使用 Python
Create/Delete Telegram Bot Commands Using Python
是否可以使用 python create/delete Telegram Bot 的新命令?我知道 BotFather 可以使用 /setcommands
创建命令,但我想看看我是否可以使用 Python 自动创建命令列表。我正在使用 pyTelegramBotAPI
与机器人互动。
例如,我可以批量处理以下命令创建而无需在 Telegram 移动或桌面应用程序中键入它们吗?
command1 - Description for command 1
command2 - Description for command 2
command3 - Description for command 3
我想用可用命令帮助用户,只要他们输入 /
我希望 Telegram 自动显示它们 /command1
、/command2
、/command3
.
我尝试了以下方法,但似乎不起作用。 None 的命令将在应用程序中输入 /
后显示。
import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands('command1')
tb.set_my_commands('command2')
tb.set_my_commands('command3')
最后,Telegram 是否允许使用 Python 删除命令?
虽然没有指南,但一切都很简单。
<pre><code>import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands([
telebot.types.BotCommand("/start", "main menu"),
telebot.types.BotCommand("/help", "print usage")
])
所以我建议不需要删除命令,因为它们每次都会覆盖 set_my_commands 运行。
是否可以使用 python create/delete Telegram Bot 的新命令?我知道 BotFather 可以使用 /setcommands
创建命令,但我想看看我是否可以使用 Python 自动创建命令列表。我正在使用 pyTelegramBotAPI
与机器人互动。
例如,我可以批量处理以下命令创建而无需在 Telegram 移动或桌面应用程序中键入它们吗?
command1 - Description for command 1
command2 - Description for command 2
command3 - Description for command 3
我想用可用命令帮助用户,只要他们输入 /
我希望 Telegram 自动显示它们 /command1
、/command2
、/command3
.
我尝试了以下方法,但似乎不起作用。 None 的命令将在应用程序中输入 /
后显示。
import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands('command1')
tb.set_my_commands('command2')
tb.set_my_commands('command3')
最后,Telegram 是否允许使用 Python 删除命令?
虽然没有指南,但一切都很简单。
<pre><code>import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands([
telebot.types.BotCommand("/start", "main menu"),
telebot.types.BotCommand("/help", "print usage")
])
所以我建议不需要删除命令,因为它们每次都会覆盖 set_my_commands 运行。