Python Telegram机器人程序daily_routine回调未从JobQueue触发



我有以下机器人:

class Bot:
def __init__(self, handlers: list[BaseHandler], daily_routines):
self.application = Application.builder().token(BOT_TOKEN).build()
for handler in handlers:
self.application.add_handler(handler)
self.job_queue = JobQueue()
self.job_queue.set_application(self.application)
for routine in daily_routines:
self.job_queue.run_daily(routine, time=datetime.time(hour=15, minute=49,
tzinfo=pytz.timezone('Asia/Jerusalem')))
def __call__(self, *args, **kwargs):
self.application.run_polling()

if __name__ == "__main__":
_handlers = [
...
]
bot = Bot(_handlers, [daily_routine])
bot()

daily_routine定义为:

async def daily_routine(context: CallbackContext) -> None:
job = context.job
await context.bot.send_message(job.chat_id, text="HELLO")

daily_routine回调未在指定时间触发。

我怎样才能让它工作?

您没有startJobQueue,因此它不会处理任何作业。

我建议只使用ApplicationBuilder为您提供的JobQueue实例,即self.application.job_queueApplication.run_polling已经负责启动和停止该实例。


免责声明:我目前是python-telegram-bot的维护者。

最新更新