L
L
Land2282021-10-18 21:05:00
Python
Land228, 2021-10-18 21:05:00

How to implement transition on Inline buttons using call.data?

Button handler "Ring selected", "Chain selected" does not work

import config
import telebot
from telebot import types
bot = telebot.TeleBot(config.token)

@bot.callback_query_handler(func=lambda call:True)
def answer(call):
    if call.data=='yes':
        markup_inline = types.InlineKeyboardMarkup()
        item_ring = types.InlineKeyboardButton(text="Кольцо", callback_data='ring')
        item_chain = types.InlineKeyboardButton(text="Цепочка", callback_data="chain")
        markup_inline.add(item_ring, item_chain)
        bot.send_message(call.message.chat.id, "Какой вид украшения вы хотите заказать?", reply_markup=markup_inline)
    elif call.data=='no':
        bot.send_message(call.message.chat.id, 'До свидания!')
@bot.callback_query_handler(func=lambda call:True)
def step(call):
    if call.data=="ring":
        bot.send_message(call.message.chat.id, "Выбрано кольцо")
    elif call.data=="chain":
        bot.send_message(call.message.chat.id, "Выбрана цепочка")
if __name__ == '__main__':
    bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
Philip Schultz, 2021-10-18
@Filipp_SC

@dp.callback_query_handler(lambda c: c.data == 'ring’)
def step(call):

You can use bot.edit_message so that the bot changes the previous message, but then, in addition to chat_id, you need to specify another message_id
if call.data, respectively, you do not need to do

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question