Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if message.content on Discord contains a file?

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?

like image 495
cute Avatar asked Jan 15 '18 00:01

cute


2 Answers

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

like image 144
ADug Avatar answered Oct 21 '22 16:10

ADug


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.

like image 1
Raymond Zhang Avatar answered Oct 21 '22 18:10

Raymond Zhang