像python-telegram-bot一样调度

发布于 2025-02-06 06:42:52 字数 720 浏览 2 评论 0原文

我现在正在玩 /学习Python 1周 - 所以我很新。 我使用 python-telegram-bot 成功实施了一个工作电报机器人。 我使用apscheduler创建了一个工作脚本,而没有机器人,我想为我的机器人实施相同的计划。

无机器人的工作:

sched = BackgroundScheduler()
sched.add_job(my_funct, 'cron', day_of_week = 'mon-fri,sun', hour='11,15,19,23', minute = 55)

不使用机器人:

context.job_queue.run_custom(my_funct, 'cron', days = 'mon-fri,sun', hour='11,15,19,23', minute = 55)

我得到所有使用过的关键字的“ typeError:run_custom()获得了意外的关键字参数...”。 根据 telethon-bot文档< /a>调度程序基于apscheduler。但是我找不到有关如何正确使用该功能的任何线索。

I am playing / learning python now of 1 week - so I am quite new.
I implemented successfully a working Telegram Bot using python-telegram-bot.
I created a working script using APScheduler without the bot and I would like to implement the same scheduling for my bot.

Working without the bot:

sched = BackgroundScheduler()
sched.add_job(my_funct, 'cron', day_of_week = 'mon-fri,sun', hour='11,15,19,23', minute = 55)

Not working with the bot:

context.job_queue.run_custom(my_funct, 'cron', days = 'mon-fri,sun', hour='11,15,19,23', minute = 55)

I get "TypeError: run_custom() got an unexpected keyword argument ..." for all of the used keywords.
According to the telegram-python-bot documentation the scheduler is based on APScheduler. But I did not find any clues on how to use the function correctly.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

会傲 2025-02-13 06:42:52

似乎您以错误的方式提供关键字参数。根据您包含的文档链接,关键字参数应传递给job_kwargs

像这样:

context.job_queue.run_custom(
    my_funct,
    job_kwargs={
        'trigger': 'cron',
        'days': 'mon-fri,sun',
        'hour': '11,15,19,23',
        'minute': 55,
    },
)

Seems like you're providing the keyword arguments the wrong way. According to the documentation link you included, the keyword arguments should be passed to job_kwargs.

Like this:

context.job_queue.run_custom(
    my_funct,
    job_kwargs={
        'trigger': 'cron',
        'days': 'mon-fri,sun',
        'hour': '11,15,19,23',
        'minute': 55,
    },
)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文