So, I am trying to create a bot for quizzes and, basically, when I press this Add question
button, nothing happens. Tried multiple ways to handle this button and it still does nothing. I am really new to TeleBot and would appreciate it a lot if you helped me, where is the mistake?
def create_quiz(call):
bot.send_message(call.message.chat.id, 'What do you want to name this quiz?')
bot.register_next_step_handler(call.message, handle_quiz_name)
def handle_quiz_name(message):
quiz_name = message.text
quiz_id = add_quiz(quiz_name)
markup = types.InlineKeyboardMarkup()
add_question_button = types.InlineKeyboardButton("Add Question", callback_data=f"add_question_{quiz_id}")
markup.add(add_question_button)
bot.send_message(message.chat.id, f'Great! A quiz with the name of "{quiz_name}" is created.', reply_markup=markup)
# Handling "Add question"
@bot.callback_query_handler(func=lambda call: call.data.startswith('add_question_'))
def add_question(call):
quiz_id = call.data.split('_')[2]
bot.send_message(call.message.chat.id, 'Send your question:')
call.quiz_id = quiz_id
bot.register_next_step_handler(call.message, handle_question_text)
Tried to test it like this. Didn’t put out anything in the console either. Think the problem might be with creating a button itself?
def handle_quiz_name(message):
quiz_name = message.text
quiz_id = add_quiz(quiz_name)
markup = types.InlineKeyboardMarkup()
add_question_button = types.InlineKeyboardButton("Add question", callback_data=f"Add question")
# add_question_button = types.InlineKeyboardButton("Add question", callback_data=f"add_question_{quiz_id}")
print("Callback_data for 'Add question':", f"add_question_{quiz_id}")
markup.add(add_question_button)
bot.send_message(message.chat.id, f'Great! A quiz with the name of "{quiz_name}" is created.', reply_markup=markup)
@bot.callback_query_handler(func=lambda call: call.data == 'Add question')
def test(call):
print('You have pressed the button!')
potentially smart is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.