Reputation:
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?
Upvotes: 0
Views: 366
Reputation: 7068
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
.
Upvotes: 0