A
A
Alexey2020-10-17 20:21:22
Python
Alexey, 2020-10-17 20:21:22

Telebot library, inline button has no reaction, how to solve?

markup_inline = types.InlineKeyboardMarkup(row_width=1)
        item_cours5 = types.InlineKeyboardButton(text = cours5, callback_data='1')
        item_cours6 = types.InlineKeyboardButton(text = cours6, callback_data='2')
        item_cours7 = types.InlineKeyboardButton(text = cours7, callback_data='3')
        item_cours8 = types.InlineKeyboardButton(text = cours8, callback_data='4')
        item_cours9 = types.InlineKeyboardButton(text = cours9, callback_data='5')
        markup_inline.add(item_cours5, item_cours6, item_cours7, item_cours8, item_cours9)
I connected the keyboard, everything works fine, it appears under the desired message
@bot.callback_query_handler(func = lambda message: True)
def answer(message):
        if message.data == '1':
            bot.send_message(message.chat.id, "Открываю...")
Here is the inline button handler, as soon as it did not twist, there was no reaction ...

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-10-17
@resolut1123

no reaction

But what about the error?
AttributeError: 'CallbackQuery' object has no attribute 'chat'

See examples of Inline keyboard https://github.com/eternnoir/pyTelegramBotAPI/blob...
Do it print(message)in the function answer, you will see that there is no such field as chat

A
Azama Vaniev, 2020-10-17
@azamatvaniev

Try this:
keyboard = types.InlineKeyboardMarkup()
rele1 = types.InlineKeyboardButton(text="cours5", callback_data="1")
rele2 = types.InlineKeyboardButton(text="cours6", callback_data="2")
backbutton = types. InlineKeyboardButton(text="Back", callback_data="mainmenu")
keyboard.add(rele1)
keyboard.add(rele2)
keyboard.add(backbutton)
or try removing the quotes in cours

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question