Python Telegram Bot Job Queue



我试图设置一个每小时发送消息的机器人,我尝试了我在谷歌和堆栈溢出中找到的一切,但似乎无法使作业队列工作。这是我的代码,我基本上是从官方的python-telegram-bot git hub获取的。这是代码,任何帮助都是非常感谢的。

from telegram.ext import Updater
u = Updater('bot_token', use_context=True)
j = u.job_queue
def callback_minute(context):
context.bot.send_message(chat_id='my_chat_id', text='One message every minute')
job_minute = j.run_repeating(callback_minute, interval=10)
u.start_polling()
u.idle()

这是我得到的traceback

Error submitting job "callback_minute (trigger: interval[0:00:10], next run at: 2021-09-06 08:50:47 UTC)" to executor "default"
Traceback (most recent call last):
File "C:UsersaeriuAppDataLocalProgramsPythonPython39libsite-packagesapschedulerschedulersbase.py", line 974, in _process_jobs
executor.submit_job(job, run_times)
File "C:UsersaeriuAppDataLocalProgramsPythonPython39libsite-packagesapschedulerexecutorsbase.py", line 71, in submit_job
self._do_submit_job(job, run_times)
File "C:UsersaeriuAppDataLocalProgramsPythonPython39libsite-packagesapschedulerexecutorspool.py", line 22, in _do_submit_job
f = self._pool.submit(run_job, job, job._jobstore_alias, run_times, self._logger.name)
File "C:UsersaeriuAppDataLocalProgramsPythonPython39libconcurrentfuturesthread.py", line 163, in submit
raise RuntimeError('cannot schedule new futures after '
RuntimeError: cannot schedule new futures after interpreter shutdown

当你按下start键时:

from telegram.ext import Updater, CommandHandler
updater = Updater('YOUR_BOT_TOKEN')
def callback_minute(context):
context.bot.send_message(chat_id='my_chat_id', text='One message every minute')
def set_timer(update,context):
due= 10  
chat_id = update.message.chat_id
context.job_queue.run_repeating(self.callback_minute, due, context=chat_id, name=str(chat_id))
dispatcher = updater.dispatcher
dispatcher.add_handler(CommandHandler("start", self.set_timer))
updater.start_polling()
updater.idle()

相关内容

  • 没有找到相关文章

最新更新