Answer the question
In order to leave comments, you need to log in
How to implement a telegram bot quiz?
Hey!
I plan to create a quiz that will run on a specific button.
How to implement it?
Text and four buttons appear (keyboard not a problem). The text must be taken from the database and sent as a message. The user presses one of the buttons and a message arrives - this is the correct / incorrect answer.
And immediately a new question appears with the same keyboard, but with a different correct letter.
How to implement it correctly?
Answer the question
In order to leave comments, you need to log in
Create a database with columns:
id , question, correct answer, wrong answer
Create a callback button, when clicked, all questions are pulled from the database and 1 random one of them is displayed to the user, looks something like this:
questions = db.execute('SELECT * FROM QUESTIONS')
question = random.choice(questions)
answered_ids = db.execute('SELECT answered_ids FROM USERS WHERE (user_id IS ?)', (callback_query.from_user.id,))
questions = db.execute('SELECT * FROM QUESTIONS WHERE id != IN(?)', (answered_ids,))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question