【问题标题】:Create/Delete Telegram Bot Commands Using Python使用 Python 创建/删除 Telegram Bot 命令
【发布时间】:2021-02-03 23:50:35
【问题描述】:

是否可以使用 python 为 Telegram Bot 创建/删除新命令?我知道 BotFather 可以使用/setcommands 创建命令,但我想看看是否可以使用 Python 自动创建命令列表。我正在使用pyTelegramBotAPI 与机器人交互。

例如,我可以在 Telegram Mobile 或 Desktop App 中不输入以下命令创建批处理吗?

command1 - Description for command 1
command2 - Description for command 2
command3 - Description for command 3

我想帮助用户使用可用的命令,一旦他们输入/,我希望 Telegram 自动向他们显示/command1/command2/command3

我尝试了以下方法,但似乎不起作用。在应用程序中输入/ 后,将不会显示任何命令。

import telebot
tb = telebot.TeleBot(TELEGRAM_TOKEN)
tb.set_my_commands('command1')
tb.set_my_commands('command2')
tb.set_my_commands('command3')

最后,Telegram 是否允许使用 Python 删除命令?

【问题讨论】:

    标签: python command telegram-bot


    【解决方案1】:

    一切都很简单,虽然没有指南。

    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 时它们都会覆盖。

    【讨论】:

      猜你喜欢
      • 2021-09-26
      • 2018-10-13
      • 1970-01-01
      • 1970-01-01
      • 2018-12-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      相关资源
      最近更新 更多