Gwendolyn97
Gwendolyn97

Reputation: 27

check if message has an attachment in Discord.py

I'm trying to create a function that will only proceed if a message has an image attached to it. What is the best way to check if a message has an image attached to it? Pseudocode would look something like this:

if message has attachement:
     do this
else:
     do other thing

Upvotes: 1

Views: 4824

Answers (1)

Harjot
Harjot

Reputation: 943

There is an attachments attribute of all the Message objects, you can just use -

if message.attachments: # if message has an attachment(s)
     #do stuff
if not message.attachments: # if message doesnt have an attachment(s)
    #do stuff
 

Reference

Upvotes: 2

Related Questions