Answer the question
In order to leave comments, you need to log in
How to make a telegram bot quiz in python?
I am learning to write telegram bots using pytelegrambotapi. Help make a quiz where the bot sends a picture, and the participant guesses where it came from (unlimited attempts). I know the principle of creating bots, I don’t know how to implement the transition to the next picture (the first function works, but after guessing the question, there is no transition to the next function)
@bot.message_handler(content_types=['text'])
def quiz1(message):
if message.text == 'Сыграть в викторину':
photo1 = open('img1.jpg', 'rb')
caption1= '1. угадай это'
bot.send_photo(message.chat.id, photo1, caption1)
@bot.message_handler(content_types=['text'])
if message.text.lower() == 'правильный ответ' :
quiz2()
def quiz2():
bot.send_message(chat.id, 'Правильно! Это было довольно легко')
photo2 = open('img2.jpg', 'rb')
caption2 = '2. это чуть сложнее'
bot.send_photo(message.chat.id, photo2, caption2)
Answer the question
In order to leave comments, you need to log in
In your second function, firstly, chat.id is used instead of message.chat.id, and secondly, in the second function, the message variable does not exist, it must be passed from the first as an argument.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question