How can I run an async function using the schedule library?

Another option is to use apscheduler‘s AsyncIOScheduler, which works more naturally with async functions (such as send_channel). In your case, you can simply write something of the form:

scheduler = AsyncIOScheduler()
scheduler.add_job(send_channel, trigger=tr)
scheduler.start()

Where tr is a trigger object. You can use either IntervalTrigger with a 1-day interval and a start date at 21:57, or a CronTrigger.

Note that at the end of your program it is recommended to call shutdown() on the scheduler object.

Leave a Comment