我有与此相同的问题thread https://stackoverflow.com/questions/61650938/telegram-bot-how-to-send-messages-daily#new-answer?newreg=4f622178fd1f44d4929ce07813997957
run_daily
没有做好它的工作。run_once
and run_repeating
工作顺利。
我不懂为什么。我测试了你的代码,但任务没有执行
import telegram.ext
from telegram.ext import Updater
import datetime
updater = Updater('My Token', use_context=True)
job = updater.job_queue
def callback_minute(context: telegram.ext.CallbackContext):
context.bot.send_message(chat_id='My Chat ID', text='One message every minute')
t = datetime.time(20, 2, 00, 000000)
job.run_daily(callback_minute,t,days=(0, 1, 2, 3, 4, 5, 6),context=None,name=None)
updater.start_polling()
updater.idle()
我尝试过这段代码 https://stackoverflow.com/questions/52556939/how-to-use-jobqueue-in-python-telegram-bot然而,但它也不起作用
from telegram.ext import Updater, CommandHandler
import datetime
def daily_job(bot, update, job_queue):
""" Running on Mon, Tue, Wed, Thu, Fri = tuple(range(5)) """
bot.send_message(chat_id='My Chat ID', text='Setting a daily notifications!')
t = datetime.time(7, 30, 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='My Chat ID', text="Some text!")
updater = Updater('My Token')
updater.dispatcher.add_handler(CommandHandler('notify', daily_job, pass_job_queue=True))
updater.start_polling()
在这两种情况下,任务都添加到jobs()
但没有完成...