P
P
p2g2022-04-15 22:04:30
Python
p2g, 2022-04-15 22:04:30

How to add a keyboard to the handler?

how to add an InlineKeyboard to the handler?

@bot.message_handler(content_types = ["text"])
def new_obmen(message):
    if message.chat.type == 'private':
        if message.text == 'Цифра':

            bot.send_message(message.chat.id, 'Понял, сейчас подготовлю меню!')

            markup = types.InlineKeyboardMarkup(row_width=2)
            item1 = types.InlineKeyboardButton("1", callback_data='b')
            item2 = types.InlineKeyboardButton("2", callback_data='l')
            

            markup.add(item1, item2)

            bot.send_message(message.chat.id, 'Цифры', reply_markup=markup)

        else:
            bot.send_message(message.chat.id, 'ывалд')

@bot.callback_query_handler(func=lambda c: True)
def callback_inline(call):
    try:
        if call.message:
            if call.data == 'b':

                bot.send_message(call.message.chat.id, '✅Ага "1" был выбран')

            if call.data == "l":            

                bot.send_message(call.message.chat.id,  text="✅Ага '2' был выбран")


             
                markup = types.InlineKeyboardMarkup(row_width=2)
                item1 = types.InlineKeyboardButton("1", callback_data='b')
                item2 = types.InlineKeyboardButton("2", callback_data='l')

                markup.add(item1, item2)

                bot.send_message(call.message.chat.id, 'только последний item работает, а первый нет.', reply_markup=markup)


    except Exception as e:
        print(repr(e))

6259bfdcc4109148374561.png
Here is the result.

And here is an example that I want to get after clicking on InlineKeyboard :
6259c0b052d42374182001.png
6259c0b87db6c287689635.png

(ps python language, I use telebot)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question