Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Implementing commands menu button for a telegram bot using telebot

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.

like image 367
Haidara Avatar asked Sep 14 '26 17:09

Haidara


1 Answers

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:

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'))
like image 195
Subham Saha Avatar answered Sep 17 '26 08:09

Subham Saha