I’m trying to make a command that deletes all messages in a Discord channel when someone types it. I wrote some code but my bot just ignores the command completely and nothing happens.
@bot.command()
async def clear_all(ctx):
await ctx.channel.purge()
await ctx.channel.send("Channel has been cleaned successfully")
What I want is when someone uses the command /clear_all, the bot should remove every message from that channel. But right now the bot doesn’t even respond when I type the command. What am I doing wrong here?
hey, make sure your bot is actually running and check if it has the right permissions to delete messages. also, verify that you have enabled the necessary intents in the Discord developer portal. it might be a simple config issue.
Your code’s mostly right but there’s a couple things to check. If you’re using slash commands, you need @bot.slash_command() not @bot.command(). For regular prefix commands, make sure you’re typing it with your bot’s prefix - like !clear_all instead of /clear_all. Also throw a limit parameter on purge() since Discord won’t bulk delete messages older than 14 days. Try await ctx.channel.purge(limit=None) or handle it in batches. I ran into the same stuff when I started - usually it’s the prefix or permissions making the bot ignore commands entirely.
Double-check your bot token and make sure the bot’s actually connected to your server. When I ran into this, it was usually because the bot wasn’t online or I forgot bot.run(token) at the end of my script. Also verify your bot has ‘Manage Messages’ permission in that channel - without it, purge won’t work even if other commands do. Try a simple ping command first to see if your bot responds at all. If that fails too, it’s a connection or setup issue, not your clear command code.