我该怎么做才能解决python中的telegram.ext.jobqueue错误?
我打算在我的代码中使用 telegram.jobqueue 以每30秒运行 news()功能。此功能在电报中为我发送文档。这是我的代码:
def start(update: Update, context: CallbackContext):
update.message.reply_text(
"Hello, Welcome to my Bot. Please write /help to see the commands available.")
context.job_queue.run_repeating(news, interval=30, first=10, context=update.message.chat_id)
def news(update: Update, context: CallbackContext):
s = io.StringIO()
csv.writer(s).writerows(newlist)
s.seek(0)
buf = io.BytesIO()
buf.write(s.getvalue().encode())
buf.seek(0)
buf.name = f'items.csv'
context.bot.send_document(chat_id=update.message.chat_id, document=buf)
以下行构成错误:
context.job_queue.run_repeating(news, interval=30, first=10, context=update.message.chat_id)
当我在电报bot中单击 /启动时,我遇到了此错误:
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/dispatcher.py", line 555, in process_update
handler.handle_update(update, self, check, context)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/handler.py", line 198, in handle_update
return self.callback(update, context)
File "/Users/arman/Downloads/test3.py", line 23, in start
context.job_queue.run_repeating(news, interval=10, first=10, context=update.message.chat_id)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/jobqueue.py", line 293, in run_repeating
j = self.scheduler.add_job(
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 434, in add_job
job = Job(self, **job_kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/job.py", line 49, in __init__
self._modify(id=id or uuid4().hex, **kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/job.py", line 180, in _modify
check_callable_args(func, args, kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/util.py", line 401, in check_callable_args
raise ValueError('The following arguments have not been supplied: %s' %
ValueError: The following arguments have not been supplied: context
我该怎么办才能解决此问题?< /strong>
I intended to use telegram.ext.JobQueue in my code to run news() function every 30 seconds. This function sends a document for me in telegram. Here is my code:
def start(update: Update, context: CallbackContext):
update.message.reply_text(
"Hello, Welcome to my Bot. Please write /help to see the commands available.")
context.job_queue.run_repeating(news, interval=30, first=10, context=update.message.chat_id)
def news(update: Update, context: CallbackContext):
s = io.StringIO()
csv.writer(s).writerows(newlist)
s.seek(0)
buf = io.BytesIO()
buf.write(s.getvalue().encode())
buf.seek(0)
buf.name = f'items.csv'
context.bot.send_document(chat_id=update.message.chat_id, document=buf)
The following line makes the error:
context.job_queue.run_repeating(news, interval=30, first=10, context=update.message.chat_id)
I got this error when I click /start in the telegram bot:
No error handlers are registered, logging exception.
Traceback (most recent call last):
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/dispatcher.py", line 555, in process_update
handler.handle_update(update, self, check, context)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/handler.py", line 198, in handle_update
return self.callback(update, context)
File "/Users/arman/Downloads/test3.py", line 23, in start
context.job_queue.run_repeating(news, interval=10, first=10, context=update.message.chat_id)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/telegram/ext/jobqueue.py", line 293, in run_repeating
j = self.scheduler.add_job(
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/schedulers/base.py", line 434, in add_job
job = Job(self, **job_kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/job.py", line 49, in __init__
self._modify(id=id or uuid4().hex, **kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/job.py", line 180, in _modify
check_callable_args(func, args, kwargs)
File "/Users/arman/anaconda3/lib/python3.8/site-packages/apscheduler/util.py", line 401, in check_callable_args
raise ValueError('The following arguments have not been supplied: %s' %
ValueError: The following arguments have not been supplied: context
What can I do to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如 tutorial ,和文档,作业回调完全用一个类型的参数
callbackContext
- 而不是两个。免责声明:我当前是
python-telegram-bot
的维护者。As detailed in the tutorial, the example and the documentation, job callbacks take exactly one argument of type
CallbackContext
- not two.Disclaimer: I'm currently the maintainer of
python-telegram-bot
.