[英]Telegram Quiz Bot with pyTelegramBotAPI
尝试使用 pyTelegramBotAPI 构建 Telegram Quiz Bot。 我正在使用 sched 来安排消息处理程序,但我不知道如何停止消息处理程序并返回到我的主脚本,它将安排下一轮。
尝试使用超时,但它不起作用!
我的代码:
import telebot
import sched, time
def listen():
print("Send my your Answer")
@bot.message_handler(func=lambda message: True, content_types=['text'])
def command_default(m):
print(m.text)
bot.polling()
API_TOKEN = 'xxxx'
s = sched.scheduler(time.time, time.sleep)
bot = telebot.TeleBot(API_TOKEN)
s.enter(50, 1, listen)
s.run()
在此用例中,您必须使用称为有限状态机 (FSM)的东西。 您跟踪用户状态,例如用户准备发送答复的状态。
这已经在 pyTelegramBotAPI 中通过next_step_handler()实现。 但是,我建议您改为创建自己的解决方案,因为包装器提供的解决方案存在很多问题。
这是一个示例(您可以翻译页面): https ://groosha.gitbooks.io/telegram-bot-lessons/content/chapter11.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.