How do you make a working purge command
I have been trying for a long time now
Voters
epicseg (3)
Here you go! This command will only work for admins.
@bot.command(pass_context=True)
@commands.has_permissions(administrator=True)
async def purge(ctx, number: int):
if not ctx.message.channel.permissions_for(ctx.message.author.guild.me).manage_messages:
await ctx.send("I do not have permission to delete messages.")
return
if number > 200:
await ctx.send("Please specify a lower number. Discord rate limits us, so we cant really go any higher :(")
return
to_delete = []
async for message in ctx.message.channel.history(limit=number+1):
to_delete.append(message)
while to_delete:
if len(to_delete) > 1:
await ctx.message.channel.delete_messages(to_delete[:100])
to_delete = to_delete[100:]
else:
await to_delete.delete()
to_delete = []
await asyncio.sleep(1.5)
epicseg (3)
Change bot to client. @CUSULe
epicseg (3)
@LD1 Better then nothing, but it’s somthing
epicseg (3)
@LD1 idk I’m not really good at coding. Srry
epicseg (3)
@LD1 okay
You would use
channel.purge()
to do this. Here is an example command:Two things to note. First off, you are using
discord.Client
instead ofdiscord.ext.commands.Bot
. You should always use Bot, never use Client (unless you're making a self bot ig).All you have to do is replace
with
Also, you should add this to your imports: