L
L
Lena Demidova2021-02-14 23:45:38
Python
Lena Demidova, 2021-02-14 23:45:38

How to make a timer in tests through a bot in Telegram?

There is a small problem. I'm sitting puzzling over how you can add a timer to the questions in the test in the realities of the Telegram API. The only thing that comes to mind is the parallel launch of the timer function with the banal time.sleep(), which, after the time has elapsed, will simply skip the question. There are no more ideas. Can eat more normal methods of creation of the timer in these realities?

I am attaching the code of how the question test works for me.

if call.data == 'q1':
        ccAnswer = types.InlineKeyboardMarkup(row_width=4)
        asnwer1 = types.InlineKeyboardButton(text="ответ1", callback_data="qa1")
        asnwer2 = types.InlineKeyboardButton(text="ответ2", callback_data="qa2")
        asnwer3 = types.InlineKeyboardButton(text="ответ3", callback_data="qa3")
        asnwer4 = types.InlineKeyboardButton(text="ответ4", callback_data="qa4")
        ccAnswer.add(asnwer1, asnwer2, asnwer3, asnwer4)
        bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id,
                              text=' '
                                   '\nответ1'
                                   '\nответ2'
                                   '\nответ3'
                                   '\nответ4'
                              ,
                              reply_markup=ccAnswer)
    if call.data == 'qa1':
        answers_dict[call.from_user.id].append()
        call.data = 'q2'
    if call.data == 'qa2':
        answers_dict[call.from_user.id].append()
        call.data = 'q2'
    if call.data == 'qa3':
        answers_dict[call.from_user.id].append()
        call.data = 'q2'
    if call.data == 'qa4':
        answers_dict[call.from_user.id].append()
        call.data = 'q2'

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question