写一个电报机器人,就出现了这样的问题。我使用 shedule 每 10 秒向用户发送一条消息:
schedule.every(10).seconds.do(get_sending_function,str(message.chat.id)).tag(str(message.chat.id))
其中 message.chat.id 只是特定用户的 id。我正在调用一个函数:
def get_sending_function(chatId):
bot.send_message(chatId, "ATTENTION! You didn't answer the questions!")
for i in db.collection('users').document('ID').get().to_dict().items():
if i[0] == str(chatId):
mas = i[1]
break
if mas[0] == False:
schedule.clear(chatId)
return
else:
return 0
这里我通过数据库获取一个特殊列中的值,如果它是 False,那么 shedule 应该停止工作。问题是,在那之后它会进行另一次发送,并且只有在那之后它才会停止工作。如何解决?
好吧,我真的不聪明。我只是在错误的地方有 send_message ......