创建作业时必须传递上下文。
您可以从页面底部附近的示例中阅读:
>>> from telegram.ext import CommandHandler
>>> def callback_alarm(bot, job):
... bot.send_message(chat_id=job.context, text='BEEP')
...
>>> def callback_timer(bot, update, job_queue):
... bot.send_message(chat_id=update.message.chat_id,
... text='Setting a timer for 1 minute!')
...
... job_queue.run_once(callback_alarm, 60, context=update.message.chat_id)
...
>>> timer_handler = CommandHandler('timer', callback_timer, pass_job_queue=True)
>>> u.dispatcher.add_handler(timer_handler)
context
当您使用和函数时run_once
,您可以将任何内容(包括电报对象、列表/字典等)传递到作业中。然后在你的回调函数中,你必须按照你所说的传递2个参数,然后通过访问获取你需要的数据。run_daily
run_repeating
bot
job
job.context