1

I created a telegram bot that sends quiz with pyrogram, but i want to get the user's answer using a method called Poll.chosen_option and then compare it with the correct answer!! But this method returns None, Please how can i solve that and get what user chosen! Here is my code:

@app.on_message(filters.private & filters.text)
async def my_quiz(client, message : Message):
    quiz() # function returns global vars question, answers, answersID
    result = await app.send_poll(chat_id=message.chat.id, question=question, options=answers, is_anonymous=False, type="quiz", correct_option_id=answerID)
    print(result.poll.chosen_option) # here it returns None, it should return the index of the answer that the user choose
AP01
  • 820
  • 1
  • 2
  • 8
louay075
  • 21
  • 3

2 Answers2

0

result will give you the return value of sendPoll - immediately after the message has been sent and before the user could have a chance to vote on the poll. You'll need to catch the poll answer event separately. TBH, I'm not familiar with pyrogram so I can't tell you how that's done in pyrogram.

CallMeStag
  • 5,467
  • 1
  • 7
  • 22
  • I didn't know how to solve it, I found a method in pyrogram.raw.functions called GetPollResults but didn't know how to work with it – louay075 Feb 21 '22 at 08:33
0

to solve this problem you can do like this

pool = None    
@app.on_message(filters.private & filters.text)
async def my_quiz(client, message : Message):
    glogal pool
    quiz() # function returns global vars question, answers, answersID
    pool = await app.send_poll(chat_id=message.chat.id, question=question, options=answers, is_anonymous=False, type="quiz", correct_option_id=answerID)
        

to get the result you have to pass to the function get_messages the chat_id and message id for the poll

@app.on_message(filters.command("result"))
async def get_result(app , message):
    result =  await app.get_messages(chat_id , poll.id)
    print(result.poll.chosen_option)