【问题标题】:Pyrogram telegram poll : how to get the chosen option from userPyrogram telegram poll:如何从用户那里获得选择的选项
【发布时间】:2023-02-12 02:47:00
【问题描述】:

我创建了一个用热图发送测验的电报机器人,但我想使用一种名为 Poll.chosen_option 的方法获得用户的答案,然后将其与正确答案进行比较! 但是这个方法没有返回,请问我该如何解决这个问题并获得用户选择的内容! 这是我的代码:

@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

【问题讨论】:

    标签: python telegram-bot pyrogram


    【解决方案1】:

    result 将为您提供sendPoll 的返回值 - 在消息发送后和用户有机会投票之前立即返回。 您需要单独捕获投票回答事件。 TBH,我不熟悉热解图所以我不能告诉你这是如何用热解图完成​​的。

    【讨论】:

    • 我不知道如何解决它,我在 pyrogram.raw.functions 中找到了一个名为 GetPollResults 的方法,但不知道如何使用它
    【解决方案2】:

    要解决这个问题,你可以这样做

    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)
            
    

    要获得结果,您必须将轮询的 chat_id 和消息 ID 传递给函数 get_messages

    @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)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多