auem
auem

Reputation: 55

How to make Autosending Telegram bot aiogram

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

Upvotes: 1

Views: 2605

Answers (1)

auem
auem

Reputation: 55

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)

Upvotes: 2

Related Questions