Answer the question
In order to leave comments, you need to log in
@callback_query_handler what am I doing wrong?
You need to make a simple bot that makes a poll and saves the answers to an array.
I do it with several nesting levels of buttons, I get two levels, but then I don’t understand, I don’t go to the next function.
there is an error at the end of the second function, how to rewrite bot.send_message(call.message.chat.id, mes_machine, reply_markup=buttons_machine) correctly so that it transfers to the processing of the third function?
@bot.message_handler(commands=['start'])
def selects_an_employee(message):
"""Функция, которая отвчает за вывод кнопок с сотрудниками"""
mes = 'Сотрудник'
buttons_employee = get_buttons(list_of_employees)
bot.send_message(message.chat.id, mes, reply_markup=buttons_employee)
@bot.callback_query_handler(func=lambda call: True)
def selects_the_machine(call):
"""Функция, которая отвечает за выбор станка"""
mes_machine = 'Станок'
buttons_machine = get_buttons(list_of_machines)
bot.send_message(call.message.chat.id, mes_machine, reply_markup=buttons_machine) # вывод меню пользователю
@bot.callback_query_handler(func=lambda callback_data: True)
def selects_a_part(call):
"""Функиця которая принимает список с наваниями деталей, выводит их на экран, и возвращает выбранную"""
mes_part = 'Деталь'
buttons_parts = get_buttons(list_of_parts)
# bot.send_message(message.chat.id, mes, reply_markup=buttons_machines)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=mes_part,
reply_markup=buttons_parts)
Answer the question
In order to leave comments, you need to log in
Python reads your code from top to bottom, and it passes the call to the first callback_handler (in fact, it should be the only one).
See callback.data for more details on using inline keyboards and passing functions to them.
Possible solution to your problem:
...
@bot.message_handler(commands=['start'])
def selects_an_employee(message):
"""Функция, которая отвечает за вывод кнопок с сотрудниками"""
mes = 'Сотрудник'
buttons_employee = get_buttons(list_of_employees)
bot.send_message(message.chat.id, mes, reply_markup=buttons_employee)
@bot.callback_query_handler(func=lambda call: True)
def callback_worker(call):
if call.data == 'stanok': # если callback кнопки равен этому значению
mes_machine = 'Станок'
buttons_machine = get_buttons(list_of_machines)
bot.send_message(call.message.chat.id, mes_machine, reply_markup=buttons_machine) # вывод меню пользователю
if call.data == 'detal': # условие, аналогичное условию выше
mes_part = 'Деталь'
buttons_parts = get_buttons(list_of_parts)
# bot.send_message(message.chat.id, mes, reply_markup=buttons_machines)
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=mes_part,
reply_markup=buttons_parts)
...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question