本文介绍了如何在 Python-telegram-bot 中使用 Jobqueue的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
通过阅读 docs 但 Jobqueue 没有按照它编写的那样工作.run_daily
方法使用 datetime.time
对象在特定时间发送消息,但此代码既不发送消息也不显示任何错误.它只是继续运行
I have able to make a bot very easily by reading the docs but Jobqueue is not working as per it is written. The run_daily
method uses a datetime.time
object to send the message at a particular time but this code neither does its job of sending a message nor shows any errors. It just keeps running
import datetime
from telegram import bot
from telegram.ext import Updater
def callback_minute(bot, job):
bot.send_message(chat_id=475838704, text='PlEaSe wOrK!')
def main():
updater = Updater()
bot = updater.bot
job = updater.job_queue
dispatcher = updater.dispatcher
job.run_daily(callback_minute, time=datetime.time(6,33,00))
updater.start_polling()
updater.idle()
if __name__ == '__main__':
main()
推荐答案
也许这会有所帮助:
from telegram.ext import Updater, CommandHandler
def daily_job(bot, update, job_queue):
""" Running on Mon, Tue, Wed, Thu, Fri = tuple(range(5)) """
bot.send_message(chat_id=<YOUR CHAT ID>, text='Setting a daily notifications!')
t = datetime.time(10, 00, 00, 000000)
job_queue.run_daily(notify_assignees, t, days=tuple(range(5)), context=update)
def notify_assignees(bot, job):
bot.send_message(chat_id=<CHAT ID>, text="Some text!")
updater = Updater(<BOT_TOKEN>)
updater.dispatcher.add_handler(CommandHandler('notify', daily_job, pass_job_queue=True))
updater.start_polling()
然后告诉机器人 /notify
这篇关于如何在 Python-telegram-bot 中使用 Jobqueue的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!