Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

query.answer from a callback not being sent to client #4558

Closed
@henriquesati

Description

@henriquesati

I'm not being able to send a response to the client usingquery.answer('text') inside a callback function.
I also tried

context.bot.answer_callback_query(callback_query_id=query.id,text="teste@@")

where query.id its retrieved fromUpdate.callback_query

intended behavior: send a new message to a user once aInlineKeyBoardButton is pressed
current behavior: the button interface appears to be loading, but no response is sent
python -V: 3.12.6
python-telegram-bot -V = 21.6
client: telegram desktop
code:

importloggingfromtelegramimportUpdate,InlineKeyboardButton,InlineKeyboardMarkup,Botfromtelegram.extimport (ApplicationBuilder,CommandHandler,CallbackContext,CallbackQueryHandler,ContextTypes,)logging.basicConfig(format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",level=logging.INFO)# set higher logging level for httpx to avoid all GET and POST requests being loggedlogging.getLogger("httpx").setLevel(logging.WARNING)logger=logging.getLogger(__name__)asyncdefstart(update:Update,context:ContextTypes.DEFAULT_TYPE):awaitcontext.bot.send_message(chat_id=update.effective_chat.id,text="I'm a bot, please talk to me!")asyncdefchain_to_send_menu(update:Update,context:CallbackContext):keyboard= [        [InlineKeyboardButton("Option 1",callback_data="option1")],        [InlineKeyboardButton("Option 2",callback_data="option2")],    ]reply_markup=InlineKeyboardMarkup(keyboard)awaitupdate.message.reply_text("Welcome! Please choose an option:",reply_markup=reply_markup    )awaitupdate.message.reply_text("Welcome!2323e an option:",reply_markup=reply_markup    )asyncdefbutton(update:Update,context:CallbackContext):query=update.callback_queryifquery.data=="option1":awaitquery.answer(text="ereeeer 1")elifquery.data=="option2":awaitquery.answer(text="ereeeer 2")else:awaitquery.answer(text="ereeeer not selected")query.answer(text="ereeeer@@1")defmain():application= (ApplicationBuilder()        .token(TOKEN)        .read_timeout(10)        .write_timeout(10)        .concurrent_updates(True)        .build()    )CommandHandler('start',start)start_handler=CommandHandler('start',start)menu_handler=CommandHandler('menu',chain_to_send_menu)x=CallbackQueryHandler(button)application.add_handler(menu_handler)application.add_handler(start_handler)application.add_handler(x)application.run_polling()if__name__=="__main__":main()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions


      [8]ページ先頭

      ©2009-2025 Movatter.jp