I’m working on a Telegram bot using the python-telegram-bot library. Right now, my buttons appear in a special menu that users have to open. But I want them to show up right away, above the text input area. This should work on both mobile and desktop versions of Telegram.
Here’s a bit of my current code:
def start(update, context):
reply_keyboard = [['Option 1', 'Option 2'], ['Option 3']]
update.message.reply_text(
'Please choose:',
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True)
)
# Later in the code
updater = Updater('YOUR_BOT_TOKEN', use_context=True)
updater.dispatcher.add_handler(CommandHandler('start', start))
How can I change this to make the buttons appear automatically, without users needing to click an extra icon? I want them to look like standard Telegram keyboard buttons. Any help would be great!
I’ve worked on several Telegram bots, and I can assure you that your current approach is actually correct for creating standard keyboard buttons. The ReplyKeyboardMarkup you’re using is precisely what generates those buttons above the text input area.
The issue you’re experiencing might be related to how you’re viewing the bot. On desktop, these buttons sometimes appear as a small keyboard icon that needs to be clicked to expand. On mobile, they should appear automatically.
To ensure they’re always visible, try setting resize_keyboard=True in your ReplyKeyboardMarkup:
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True, resize_keyboard=True)
This will make the keyboard more compact and likely to appear without extra steps. If you’re still having issues, double-check that you’re not accidentally using an inline keyboard (InlineKeyboardMarkup) instead.
hey there! i’ve dealt with this before. you’re actually pretty close! just change ReplyKeyboardMarkup to ReplyKeyboardRemove in your code. that’ll make the buttons show up right away without any extra clicks. it should work on both mobile and desktop. hope this helps!
Your current code is on the right track for creating standard keyboard buttons. The ReplyKeyboardMarkup you’re using should display buttons above the text input area by default. However, if you’re not seeing them, it might be due to client-side settings or how you’re interacting with the bot.
Try adding ‘resize_keyboard=True’ to your ReplyKeyboardMarkup like this:
reply_markup=ReplyKeyboardMarkup(reply_keyboard, one_time_keyboard=True, resize_keyboard=True)
This often helps with visibility issues. Also, ensure you’re not in a group chat, as keyboard buttons may behave differently there. If problems persist, check if your Telegram client is up to date. Let me know if you need more assistance!