A
A
AlexSeley2021-12-18 17:09:49
Python
AlexSeley, 2021-12-18 17:09:49

Why doesn't clicking on the inlinekeyboard work?

The response does not work when the button is clicked. The def callback_inline specifies that after clicking the button, the bot sends the message "Nice!".

from telebot import types
import telebot

def callback_inline(call):
    if call.message:
      if call.data == 'press':
        bot.send_message(call.message.chat.id, 'Nice!')
        print(call.message.chat.first_name, call.message.chat.id, "command=press")

@bot.message_handler(content_types=["text"])
def button(message):
    button_1 = types.InlineKeyboardMarkup()
    button1 = types.InlineKeyboardButton("Button", callback_data='press')

    button_1.add(button1)

    bot.send_message(message.chat.id, text='Press:', reply_markup=button_1)


bot.infinity_polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
shurshur, 2021-12-18
@AlexSeley

And how does the bot know that callback_inline is a callback query handler, and not an incoming audio message and not a weather request on Mars? Where does he have the right decorator?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question