简体   繁体   English

带有 pyTelegramBotAPI 的电报测验机器人

[英]Telegram Quiz Bot with pyTelegramBotAPI

Trying to build a Telegram Quiz Bot using pyTelegramBotAPI.尝试使用 pyTelegramBotAPI 构建 Telegram Quiz Bot。 I'm using sched to schedule the message Handler but i don't know how to stop the Message Handler and return to my Main Script which will scheudle the next Round.我正在使用 sched 来安排消息处理程序,但我不知道如何停止消息处理程序并返回到我的主脚本,它将安排下一轮。

Tryed to use timeout but it is not working!尝试使用超时,但它不起作用!

My Code:我的代码:

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

In this use case you have to use something called a Finite State Machine (FSM) .在此用例中,您必须使用称为有限状态机 (FSM)的东西。 You keep track of user states, such as one where the user is ready to send an answer.您跟踪用户状态,例如用户准备发送答复的状态。

This is already implemented in pyTelegramBotAPI, with the next_step_handler() .这已经在 pyTelegramBotAPI 中通过next_step_handler()实现。 However, I suggest you instead create your own solution, as the one provided by the wrapper is quite buggy.但是,我建议您改为创建自己的解决方案,因为包装器提供的解决方案存在很多问题。

Here is an example (you can translate the page): https://groosha.gitbooks.io/telegram-bot-lessons/content/chapter11.html这是一个示例(您可以翻译页面): https ://groosha.gitbooks.io/telegram-bot-lessons/content/chapter11.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 通过 pyTelegramBotAPI 在电报机器人中获取照片 - Get photo in telegram bot through pyTelegramBotAPI 电报机器人(pyTelegramBotAPI)不处理新用户加入组 - Telegram bot (pyTelegramBotAPI) does not handle new user joining group 使用 pyTelegramBotAPI 将电报机器人部署到 Heroku 时使用开放端口 - Use an open port when deploying telegram bot using pyTelegramBotAPI to Heroku 在 PyTelegramBotAPI 上运行的 Telegram Bot 错误地获取转发的消息 - Telegram Bot running on PyTelegramBotAPI is incorrectly getting forwarded messages 使用电报机器人 pytelegrambotapi 从群组回复用户的消息 - Reply to user's message from group using telegram bot pytelegrambotapi 在编写电报机器人(使用 pyTelegramBotAPI)时,我遇到错误 TypeError: 'NoneType' object is not callable - While writing a telegram bot (with pyTelegramBotAPI) I encounter an error TypeError: 'NoneType' object is not callable requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): # python telegram bot using pytelegrambotapi and Tor - requests.exceptions.ConnectTimeout: HTTPSConnectionPool(host='api.telegram.org', port=443): # python telegram bot using pytelegrambotapi and Tor 如何在电报(pytelegramBotAPI)中获取chat_id和message_id以更新电报bot(Python)中最后发送的消息 - how to get chat_id and message_id in telebot(pytelegramBotAPI) to update last sent message in telegram bot(Python) 从电报频道获取会员 ID - pyTelegramBotApi - Get members id from telegram channel - pyTelegramBotApi 无法使用 pytelegrambotapi 向 Telegram 频道发送消息 - Unable to send a message to a Telegram channel using pytelegrambotapi
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM