Telebot:如何等待用户回复超时

时间:2020-05-18 19:11:06

标签: python telegram telegram-bot python-telegram-bot

我有个问题,几个用户必须同时使用该漫游器。因此,我确保只有首先启动该机器人的用户才能主动使用该机器人。但是我想集成一个超时,以便当用户1停止键入时该机器人可以继续工作。我已经尝试使用一会儿true循环来解决此问题,该循环需要一定的时间。不幸的是,这没有用。我会接受所有想法。

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import os
import telebot
import time
import random


bot = telebot.TeleBot('XXXXX:XXXXXXXX')


@bot.message_handler(commands=['start'])
def send_welcome(message):
       id = message.from_user.id
       bot.reply_to(message, u"Hello enter information.")
       @bot.message_handler(regexp=".*") #######Here should be a timeout when the user enter nothing for 1 minute to stop this task##########
       def send_reply(message):
               id_tmp = message.from_user.id
               if id == id_tmp:
                       bot.reply_to(message, u"Thank you next step...")
               elif id != id_tmp:
                       bot.reply_to(message, u"You are in a waiting postiion.")

bot.polling()

0 个答案:

没有答案