A
A
AlexaAioGram2021-07-13 21:03:19
Python
AlexaAioGram, 2021-07-13 21:03:19

Why is call.data not responding?

@dp.callback_query_handler()
async def randws(call: CallbackQuery):
    if call.data == 'amf':
        await call.message.answer('hello')


I checked everything 1000 times, the call-back in the inline button is correct, but when I click on the button, it does not return 'hello', please help those who understand.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Bl4ckm45k, 2021-07-14
@AlexaAioGram

Your handler @dp.callback_query_handler(text='rand')accepts text, which is needed for regular buttons, after clicking which a message is sent from the user.
For example, you can implement it like this:

@dp.callback_query_handler(lambda c: c.data == 'amf')
async def randws(call: CallbackQuery):
    await call.message.answer('gggg')

In order not to create a bunch of handlers for each callback, I advise you to familiarize yourself with callback_data_factory:
Examples:
callback_data_factory_simple
callback_data_factory
Documentation:
callback_data

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question