【问题标题】:poll answer handler with pytelegrambotapi使用 pytelegrambotapi 投票回答处理程序
【发布时间】:2021-11-14 08:00:39
【问题描述】:
我使用这个发送了一个投票:
@bot.message_handler(commands=['start'])
def start(message):
bot.send_poll(message.chat.id,'choose one',['a','b','c'])
但是我怎样才能得到答案呢?
文档说:
处理投票答案 @bot.poll_answer_handler() #
但我不知道如何使用它。
【问题讨论】:
标签:
python
python-3.x
telegram-bot
py-telegram-bot-api
【解决方案1】:
您可以通过这种方式访问和打印投票答案:
@bot.poll_answer_handler()
def handle_poll_answer(pollAnswer):
print(pollAnswer)
在python中,我们可以将@符号与装饰器函数的名称一起使用,并将其放在要装饰的函数的定义之上。
所以我们把
@bot.poll_answer_handler() 在我们的 handle_poll_answer 函数之上,以便将其注册为机器人的 poll_answer_handler。
请注意,它还表示处理程序将接收PollAnswer 类型,因此我们将其作为pollAnswer 函数的参数。
将 PollAnswer 类型的对象传递给您的函数