Hey everyone! I’m just starting out with Telegram bots and I’ve come across something cool. There’s this bot that shows a menu when you type /start. The neat thing is, you don’t need to use a slash for other commands. You just tap the menu buttons.
I’m wondering how to make a similar menu for my own bot. Does anyone know the steps to create this in Bot Father? I’ve tried looking around but couldn’t find clear instructions.
Here’s a simple example of what I’m aiming for:
from telegram.ext import Updater, CommandHandler, MessageHandler
def start(update, context):
keyboard = [['Option 1', 'Option 2'], ['Option 3', 'Option 4']]
reply_markup = ReplyKeyboardMarkup(keyboard)
update.message.reply_text('Please choose:', reply_markup=reply_markup)
def main():
updater = Updater('YOUR_BOT_TOKEN', use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', start))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
Any tips or tricks would be super helpful. Thanks in advance!
It is important to note that setting up a menu in Bot Father is aimed at creating a slash command interface rather than a custom keyboard. In Bot Father you use the /setcommands option by messaging the bot, then selecting which bot to configure and providing commands with their descriptions. This results in a menu that appears when users type a slash. In contrast, your Python example builds a keyboard interface that offers clickable buttons. If you need a custom layout, managing it in your code is the more flexible approach.
hey claire29, setting up a menu in botfather is different from custom keyboards. for slash commands, use /setcommands in botfather chat. but for button menus like ur example, u gotta code it urself. botfather just handles the slash commands that show up when u type ‘/’. hope that clears things up!
I’ve gone through this process recently, and it’s actually quite straightforward. In Bot Father, you’ll want to use the /setcommands command. This allows you to define a list of commands that will appear as a menu when users click the ‘/’ symbol in the chat.
Here’s what I did:
Start a chat with @BotFather
Send /setcommands
Choose the bot you want to set up the menu for
Send a list of commands in this format:
command1 - Description of command1
command2 - Description of command2
Each command should be on a new line. After submitting, Bot Father will confirm the commands have been set.
Remember, this creates a menu of slash commands, not buttons like in your code example. For custom keyboard buttons, you’ll need to implement that in your bot’s code, as you’ve shown. The Bot Father setup is mainly for the slash command menu.
Hope this helps with your bot development!