Telegram bot menu not responding with python-telegram-bot library

I’m experiencing issues with my telegram bot menu not functioning properly. As a beginner to telegram bots and the python-telegram-bot library, I’m seeking assistance.

While the bot starts without showing any errors, it doesn’t respond when I attempt to interact with it. There are no output messages or errors in the console, which leaves me puzzled.

I’ve tried to adapt code examples from the official documentation and other examples I’ve come across, but it seems like there’s a fundamental issue with my implementation.

from telegram.ext import CommandHandler, CallbackQueryHandler, Updater
from telegram import KeyboardButton, ReplyKeyboardMarkup
from functools import wraps

BOT_TOKEN = 'your_token_here'
ALLOWED_USERS = ["user1", "user2"]
ADMIN_LIST = ["admin1"]

def admin_only(function):
    @wraps(function)
    def wrapper(update, context, *args, **kwargs):
        user = update.effective_user.username
        if user not in ADMIN_LIST:
            update.message.reply_text(f"Access denied {user}, admin required")
            return
        return function(update, context, *args, **kwargs)
    return wrapper

def authorized_only(function):
    @wraps(function)
    def wrapper(update, context, *args, **kwargs):
        user = update.effective_user.username
        if user not in ALLOWED_USERS:
            update.message.reply_text(f"Not authorized {user}!")
            return
        return function(update, context, *args, **kwargs)
    return wrapper

@authorized_only
def handle_start(update, context):
    update.message.reply_text(get_menu_text(), reply_markup=create_main_keyboard())

def create_button_grid(items, columns, top_row=None, bottom_row=None):
    grid = [items[i:i + columns] for i in range(0, len(items), columns)]
    if top_row:
        grid.insert(0, [top_row])
    if bottom_row:
        grid.append([bottom_row])
    return grid

@authorized_only
def show_main_menu(update, context):
    query = update.callback_query
    query.answer()
    query.edit_message_text(
        text=get_menu_text(),
        reply_markup=create_main_keyboard()
    )

def create_main_keyboard():
    options = [[KeyboardButton('Settings', callback_data='opt1')],
              [KeyboardButton('Restart', callback_data='opt2')],
              [KeyboardButton('Enable', callback_data='opt3')],
              [KeyboardButton('Disable', callback_data='opt4')],
              [KeyboardButton('Debug 1', callback_data='opt5')],
              [KeyboardButton('Debug 2', callback_data='opt6')]]
    markup = ReplyKeyboardMarkup(create_button_grid(options, n_cols=2))
    return markup

def get_menu_text():
    return 'Choose an option from the menu below'

bot_updater = Updater(BOT_TOKEN, use_context=True)
bot_updater.dispatcher.add_handler(CommandHandler('start', handle_start))
bot_updater.dispatcher.add_handler(CallbackQueryHandler(show_main_menu, pattern='main'))
bot_updater.start_polling()

Could anyone identify what I might be doing incorrectly? Your assistance would be greatly appreciated!

u seem to be mixing up ReplyKeyboardMarkup with callback_data. that won’t work. Callback_data is for inline keyboards, while reply keyboards just send text msgs. use CallbackQueryHandler for inline buttons or MessageHandler for reply keyboards. also, make sure your username is in the ALLOWED_USERS list, or the decorator blocks access.

The problem lies with your button setup. You’re using KeyboardButton objects with callback_data in a ReplyKeyboardMarkup, which isn’t correct. Regular keyboard buttons don’t utilize callback_data; that’s reserved for InlineKeyboardButton. Currently, tapping the buttons sends the text as messages, but no handler processes them. To resolve this, either switch to InlineKeyboardMarkup with InlineKeyboardButton or retain ReplyKeyboardMarkup by eliminating callback_data and adding a MessageHandler for the button text. Additionally, ensure your username is included in the ALLOWED_USERS list, as the decorator will block access without alerting you.