gpt4 book ai didi

Implementing commands menu button for a telegram bot using telebot(使用telebot实现电报机器人的命令菜单按钮)

转载 作者:bug小助手 更新时间:2023-10-22 16:56:53 37 4
gpt4 key购买 nike



I've been trying to set the list of commands for my telegram bot but it doesn't work, here's what I'm doing:

我一直在尝试为我的电报机器人设置命令列表,但它不起作用,我正在做的是:


bot = telebot.TeleBot("TOKEN")
bot.set_my_commands(commands = ['start','go','help'])
bot.set_chat_menu_button(bot.get_me().id, types.MenuButtonCommands(type = 'commands'))

can anyone help me to figure it out? Thx anyway.

有人能帮我弄清楚吗?不管怎样。


更多回答

I figured it out, the list of commands must be in type "BotCommand" passed to the method "set_my_commands" without any use for the method "set_chat_menu_button".

我发现,命令列表必须是传递给方法“set_my_commands”的类型“BotCommand”,而不使用方法“set_chat_menu_button”。

优秀答案推荐

You have given bot.get_me().id which gives user_id of the bot. But it needs the chat_id. So give message.chat.id.
And the bot.set_my_commands() takes a list of BotCommands. But you have given an ordinary list.
Try:

你已经给了bot.get_me().id,它给出了机器人的user_id。但它需要chat_id。所以给message.chat.id。然后bot.set_my_commands()获取一个BotCommands列表。但你给出了一个普通的清单。尝试:


c1 = types.BotCommand(command='start', description='Start the Bot')
c2 = types.BotCommand(command='help', description='Click for Help')
c3 = types.BotCommand(command='go', description='Something')
bot.set_my_commands([c1,c2,c3])
bot.set_chat_menu_button(message.chat.id, types.MenuButtonCommands('commands'))

更多回答

37 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com