How to convert an image to URL Discord Py

Viewed 5189

If there any way to convert an image to an Url?

Like, if "x" admin do a !Warn Simplezes Reason (Reason should be a text accompanied by an image that the admin will send) when the admin send the command, the bot should display something like Simplezes has been warned. Reason: and show an URL to the picture that the admin sent

1 Answers

In discord.py you've an attribute to the Message object that called "attachments", it's a list of all the attachments of the message ("Attachment" class [DISCORD.PY DOCS]).

Now we know that this attribute contains a list of "Attachment" class. The "Attachment" class have an attribute called "url" and that's the url of the attachment.

That what you was looking for ^^, now for example you can do:

for attachment in message.attachments:
    # Do what you want with attachment.url
    print(attachment.url)

I recommend you also to save the discord.py docs

And join to discord.py discord server for fast response on your questions related to discord.py!

Related