Discord.py Bot Autodelete

Viewed 359

Im new to python (i learned the basics at a school course), and for the moment im trying to create simple bots for my discord server. And for the moment, the bot i really want, is an autodelete bot so that i can say, (for example) delete every message in the ...Channel after 24h. because i really dont wanna do that manually. I know there are a few good bots that do that,
but for example MEE6 wants me to buy Premium to use the funktion.The other reason why i dont want to use any finished bot is that i really want to understand and learn the code,
i watched many tutorials and tried to put the parts of the scripts that i understood together, but it did not work. I also didnt find a tutorial which explained it to me so that i understood, so now im here and hope that im going to understand it. I hope there are some ppl to help me. :)

Thanks
-Yami.Code

@bot.event()
async def on_ready(ctx):
    while requirement == 1:
        await ctx.channel.purge
        time.sleep(20)

#the Error is:

line 11, in <module>
    @bot.event()
TypeError: event() missing 1 required positional argument: 'coro'

Process finished with exit code 1
1 Answers
  1. You shouldn't call bot.event (remove the parenthesis),
  2. time.sleep is a blocking call, use asyncio.sleep instead (What does "blocking" mean)
  3. on_ready doens't take ctx as an argument, if you want to send a message to a channel you should get the channel object first, and then use the send method
  4. You're missing a parenthesis in your channel.purge method...
import asyncio # if you haven't already

@bot.event
async def on_ready():
    channel = bot.get_channel(channel_id) # replace `channel_id` with an actual channel ID
    while requirement == 1:
        await channel.purge(limit=x) # change `x` accordingly...
        await asyncio.sleep(20)
Related