如何制作自动发送 Telegram 机器人 aiogram

发布于 01-17 12:36 字数 104 浏览 5 评论 0原文

如何在特定时间(10:00)每天在电报机器人中自动发送消息,以及每周在20:00

AIPROM

上每周一次,我试图通过计划模块实现它,但是在发送时会出现错误一条消息

How to make automatic sending of messages in the telegram bot daily at a certain time (10:00), as well as weekly on Sundays at 20:00

Aiogram

I tried to implement it through the schedule module, but it gives an error when sending a message

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

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

发布评论

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

评论(1

熟人话多2025-01-24 12:36:01
import asyncio
import aioschedule

async def noon_print():
    print("It's noon!")

async def scheduler():
    aioschedule.every().day.at("12:00").do(noon_print)
    while True:
        await aioschedule.run_pending()
        await asyncio.sleep(1)

async def on_startup(_):
    asyncio.create_task(scheduler())

if __name__ == '__main__':
    executor.start_polling(dp, skip_updates=False, on_startup=on_startup)
import asyncio
import aioschedule

async def noon_print():
    print("It's noon!")

async def scheduler():
    aioschedule.every().day.at("12:00").do(noon_print)
    while True:
        await aioschedule.run_pending()
        await asyncio.sleep(1)

async def on_startup(_):
    asyncio.create_task(scheduler())

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