Reputation: 1
Im making a image-editing bot and i cant figure out how to check if sent attachment is image.
So im wondering if theres any way to check it, thanks for answer.
I tried:
if = ctx.message.attachments[0].image == True:
# do stuff
But sadly got error (i was expecting it!!!!)
Upvotes: 0
Views: 1482
Reputation: 5650
The discord.Attachment
class has a content_type
attribute that contains the MIME-type of the attachment. For example, if the user uploads a .png
file, the value of this will be "image/png"
. Checking if it starts with "image/"
is probably good enough for your use-case, unless you only want to allow very specific types of images.
Note: this field can be None
if the value is unknown for whatever reason.
Upvotes: 1