Answer the question
In order to leave comments, you need to log in
How to make inline menu change by pressing buttons in TelegramBot (TeleBot)?
I want to make it so that when I click on the Inline button, the following Inline menu is displayed to me in the same message.
Code snippet:
@bot.message_handler(content_types=['text']) # Respond to sent messages. Processes what was written to the bot
def text_type_1st(message):
if message.chat.type == 'private':
if message.text == 'Auto':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton( "RENO", callback_data='reno')
item2 = types.InlineKeyboardButton("VAZ", callback_data='vaz')
markup.add(item1, item2)
bot.send_message(message.chat.id, 'Enter car make?' ,
if message.text == 'Select Model':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Logan", callback_data='logan')
item2 = types.InlineKeyboardButton("Kaptur", callback_data=' kaptur')
item3 = types.InlineKeyboardButton("Duster", callback_data='daster')
markup.add(item1, item2, item3)
bot.send_message(message.chat.id, 'Select a model and click the button', reply_markup= markup)
# handle event
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
try:
if call.message:
if call.data == 'reno':
# msg = bot.send_message(call.message.chat.id, "Enter and send the VIN of the car,\n"
# "what you want to find!", parse_mode='html')
msgCarMark = bot.edit_message_text(chat_id=call. message.chat.id, message_id=call.message.id,
text="Select model", parse_mode='html')
bot.register_next_step_handler(msgCarMark, text_type_2st)
if call.data == 'logan':
bot.send_message(call .message.chat.id, 'That's great ')
if call.data == 'kaptur':
bot.send_message(call.message.chat.id, 'That's great')
if call.data == 'daster':
bot.send_message(call.message.chat.id, 'That's great')
elif call.data == 'vaz':
pass
except Exception as cb:
print("Problem in callback !", cb)
Answer the question
In order to leave comments, you need to log in
In callback_inline :
msgCarMark = bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.id,
text="Выберите модель", parse_mode='html', reply_markup = markup)
There is a special function
edit_message_reply_markup(chat_id =..., message_id =..., reply_markup =...)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question