[Python] InlineKeyboardButton with callback_data doesn't work

Discussão em 'Python' iniciado por Stack, Agosto 15, 2025.

  1. Stack

    Stack Membro Participativo

    InlineKeyboardButton with callback_data doesn't work. When I click on it, nothing happens.

    Here is how I create the button:

    from django.apps import apps
    from asgiref.sync import sync_to_async
    from telegram import Update, InlineKeyboardMarkup, InlineKeyboardButton, WebAppInfo
    from telegram.ext import CommandHandler, ApplicationBuilder, MessageHandler, filters, CallbackQueryHandler

    async def start(self, update: Update, context):
    keyboard = InlineKeyboardMarkup([
    [InlineKeyboardButton("Already registred", callback_data="already_registered")],
    [InlineKeyboardButton("Register", web_app=WebAppInfo(url=WEB_APP_URL))]
    ])

    await update.message.reply_text(
    "Welcome",
    reply_markup=keyboard
    )
    return


    This is the callback query handler:

    async def button(self, update: Update, context):
    query = update.callback_query
    if not query:
    return

    await query.answer()

    if query.data == "already_registered":
    await context.bot.send_message(
    chat_id=update.message.chat_id,
    text='Good'
    )
    return


    and this is how I run:

    def run(self):
    TOKEN = apps.get_model('app.Config').objects.get_mailing_tg_bot_token()
    app = ApplicationBuilder().token(TOKEN).build()
    app.add_handler(CommandHandler('start', self.start))
    app.add_handler(CallbackQueryHandler(self.button))

    Continue reading...

Compartilhe esta Página