On my Discord server, I have a #selfies channel where people share photos and chat about them. Every now and then, I would like to somehow prune all messages that do not contain files/images. I have tried checking the documentation, but I could see not see any way of doing this. Is it not possible?
You can iterate through every message and do:
if not message.attachments:
...
message.attachments returns a list and you can check if it is empty using if not
I'm not too familiar with discord.py (since I use discord.js), but if this is similar to discord.js there should be a message event. This event will run on every message, which is ideal for what you are searching for now. Now for the pseudocode...
//written in javascript
Message event:
On each message {
if(message.attachments.size <= 0) {
message.delete();
}
}
The general idea is that using the message event, (so on each message), you check if the message's attachments list is greater than 0 (meaning it contains a file or image) and if it is not, call the delete() function in python to delete the message.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With