Reputation: 35
So I need to know how to make my python discord bot do something at a certain time because I want it to clear all messages in a channel at around 5:00am when no one is on I will be using the date time module but the problem is I do not want it to interfere with the rest of my bot is there any way I can do this. I know that there are other threads about this but none of them bring up the part about interference with the rest of there bot. And I am using repl.it to run the bot in case that is needed to be known.
Upvotes: 1
Views: 272
Reputation: 159
You can create an asynchronous background task. During bot startup, calculate how many seconds are left to 5 AM and then sleep the task until then.
There is no reason that it should "interfere" with the rest of your code. I assume that you tried using blocking functions such as time.sleep()
. You can use asyncio.sleep()
instead.
Upvotes: 1