At this moment, purge can only purge the most recent messages, making it impossible to purge, say, pinned messages only. To fill the gap, purgepy has born.
We strongly recommend you to learn Python (especially discord.py) beforehand.
Python examples | ||
---|---|---|
Script | Will find… | Remarks |
msg.author.bot | Messages sent by bots | |
not msg.author.bot | Messages sent by humans | |
msg.author.name=="John" | Messages sent by anyone with username "John" | |
msg.author.discriminator=="1234" | Messages sent by anyone with discriminator 1234 | |
await msg.guild.get_role(12345678901234567) in msg.author.roles | Messages sent by anyone with a role | Remember to put the actual role ID. |
len(msg.author.embeds)==0 | Messages with no embeds | len(list) returns the length of the list |
len(msg.author.role_mentions)>0 | Messages with at least one @Role mention | |
len(msg.reactions)>1 | Messages with at least two reactions | |
len(msg.stickers)>2 | Messages with at least three stickers | |
len(msg.mentions)>3 | Messages that notified at least four members | |
msg.pinned | Messages that are pinned | |
msg.edited!=None | Messages that have been edited | Use == instead of != for messages that haven't been edited. |
msg.reference!=None | Messages that are replies to other messages | Use == instead of != for messages that aren't replies. |
To use the script, run purgepy Number(Integer) Script(Text+).
Now, you might want to focus on what's being sent rather than the properties of the message itself. For example, you want to filter only messages that contains a bad word, or those that include Email addresses. So here comes another handy table:
Basic Regex examples | ||||
---|---|---|---|---|
Regex | Will filter… | Example match | Example non-match | Remarks |
[^]* | Any message | (Anything) | - | [^] means "any character" * means "as many as possible" |
[^]*! | Any message that ends with an exclamation mark | Lorem! | Lorem! Ipsum | |
[^ab][^]* | Any message that does not start with 'a' or 'b' | sad | ad | [^…] means "any character except" |
\+[^]* | Any message that starts with '+' (Useful for filtering bot commands!) | +1=1 | 1+2=3 | […] means "any character in" The plus sign has to be escaped! |
\+[^ ]* | Any message that starts with '+' but does not start with '+' and a space | +test | + test | |
[\d]* | Any message with only digits 0~9 | 123 | 123+1 | \d represents digits |
[\d\w]* | Any message with only alphabets, digits, and underscores | Lorem_ipSUM_dolor | Lorem ipSUM dolor | \w represents alphabets and underscore Items in sq. brackets can be combined |
.{10} | Any message with 10 characters that are not line breaks | LoremIpsum | Ipsum Dolor |
. (dot) means "any character except line break" {n} means "exactly n characters" |
.{10} | Any message with 10 characters that are not line breaks | Dolor+ Sit | Dolor+ Sit |
. (dot) means "any character except line break" {n} means "exactly n characters" |
\S{5,} | Any message with at least 5 characters that are not whitespaces | LoremIpsumDolorSitAmet | Lorem Ipsum Dolor Sit Amet |
\S means "any character except whitespaces" Whitespaces include spaces, line breaks and their variations {n,} means "more than or equal to n characters" Square brackets can be omitted when there is only one item |
[A-Z]{1,3} | Any message with at most 3 characters between A and Z (In Unicode number) |
SIT | Sit | [m-n] represents all characters in between (inclusive) Note that you cannot omit square brackets in this case! |
[!A-Za-z]{1,5} | Any message with at most 5 characters that are between A and Z, between a and z, or an exclamation mark | Aah! | Aha? | Ranges and individual characters can be combined in sq. brq. Do not use [A-z] as it will match too many characters |
Usable Regex examples | ||||
---|---|---|---|---|
Regex | Will filter… | Example match | Example non-match | Remarks |
[^]*([^]{3,})[^]+\1[^]* | Any message with a segment repeated twice or more, segment length ≥3 | Lorem ipsum ip | Pandan | The rounded brackets create a group that can be referenced to, and the \1 refers to the first group. |
[^]*[\w\.-]{2,300}@[\w\.-]+\.[a-z]{2,3}(?:\.[a-z]{2})?[^]* | Any message with a valid Email address | Lorem@ipsum.edu.zz AND Lorem@ipsum.edu | Lorem@ipsum@dolor.com | This is a short way to validate Email addresses. However, it still allows for certain illegal addresses. |