我该怎么做才能解决python中的telegram.ext.jobqueue错误?

发布于 2025-02-10 17:20:07 字数 2390 浏览 2 评论 0原文

我打算在我的代码中使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

年华零落成诗 2025-02-17 17:20:07

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文