Skip to content
Sign upLog in
← Back to Community

How can I make a purge command for discord.py?

Profile icon
Blessedchan

Trying to make it so that you can run a command where when you run "?purge 12"(12 can be any number), it deletes 12 previous messages in order(from new to old).
Don't know how to remove the "?purge " from it and then save the 12 as a variable.
Example(another bot):
image

Voters
Profile icon
Blessedchan
Comments
hotnewtop
Profile icon
saicharithomg20

yo

Profile icon
Coder100
Profile icon
Blessedchan

@Coder100
did not work for some reason
image

Profile icon
Coder100

hmm

@Blessedchan

Profile icon
Coder100

oh, you did it wrong, you added an extra arg, your function has to be:

@client.event async def on_message(channel): message = channel # now add more code, like the if ...

@Blessedchan

Profile icon
Blessedchan

@Coder100

i tried that, then it said it was missing an arg, same with the other way around

Profile icon
Coder100

@Blessedchan
watttt send screenshot

Profile icon
Blessedchan

@Coder100
works now, but now there's this:

image

Profile icon
Coder100

oops did it backwards, have:
message=channel


@Blessedchan

Profile icon
Blessedchan

@Coder100
I use the very bottom result, correct?
image

Profile icon
Coder100

@Blessedchan
no, what you already have

Profile icon
Coder100

@Blessedchan

async def on_message(channel): message = channel if message.content.startswith("?purge"): # ...
Profile icon
Blessedchan

@Coder100

Does not return any output, or show any error.
image

Profile icon
Coder100

ok, so like a delete multiple messages?

Profile icon
Blessedchan

yeah

@Coder100