How to create a telegram bot quiz with single correct answer?

I’m working on a telegram bot that needs to create quiz questions with only one right answer. Here’s what I have so far:

@bot.message_handler(func=lambda message: True)
def handle_quiz(message):
    if message.text == 'quiz':
        quiz_question = "What is the largest planet in our solar system?"
        answer_choices = ["Jupiter", "Saturn", "Earth", "Mars"]
        bot.send_poll(message.chat.id, quiz_question, answer_choices)

Right now my bot accepts any answer as correct which is not what I want. I need to make it so only one specific answer is marked as the correct one. The bot should work as a proper quiz where users get feedback on whether they chose right or wrong. I don’t want to use inline buttons for this, just the regular poll feature. How can I modify my code to specify which option is the correct answer?

To ensure that your Telegram bot correctly identifies the single right answer for your quiz, you need to set the type parameter to ‘quiz’ and use the correct_option_id to indicate the index of the correct answer. For example:

bot.send_poll(
    message.chat.id,
    quiz_question,
    answer_choices,
    type='quiz',
    correct_option_id=0
)

In this instance, since Jupiter is the correct answer and it is the first option, you specify correct_option_id=0. Using the quiz type allows immediate feedback to users, showing them whether their choice was correct or not.

add the correct_option_id param to your send_poll: bot.send_poll(message.chat.id, quiz_question, answer_choices, correct_option_id=0) since Jupiter’s index 0. also, don’t forget is_quiz=True or it’ll just be a reg poll.

You’re missing two key parameters: type='quiz' and correct_option_id. Since Jupiter’s at index 0 in your array, here’s what you need:

bot.send_poll(
    message.chat.id, 
    quiz_question, 
    answer_choices, 
    type='quiz',
    correct_option_id=0
)

I’d also add an explanation parameter like explanation="Jupiter is the largest planet by mass and volume" - helps users learn from their mistakes. Without these parameters, Telegram just treats it as a regular poll with no right/wrong feedback.