Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use a local file as the set_image file discord.py

I am aware that in discord.py, you can make the set_image of an embed a url of an image. But, I want to use a local file on my computer for the set_image instead of a url of an image.

embed = discord.Embed(title="Title", description="Desc", color=0x00ff00)
embed.set_image(url = "https://example.com/image.png") #this is for set_image using url

How can I achieve this? Is there another function or something?

like image 665
Armster Avatar asked Dec 06 '22 08:12

Armster


1 Answers

Ok I just got it. The code for it is the following:

embed = discord.Embed(title="Title", description="Desc", color=0x00ff00) #creates embed
file = discord.File("path/to/image/file.png", filename="image.png")
embed.set_image(url="attachment://image.png")
await ctx.send(file=file, embed=embed)

The only thing you should be changing is line 2 where it says "path/to/image/file.png"

Note: on lines 2 and 3, there is an image.png. Fret not about it since thats what Discord is calling the uploaded file (Example: I have a file called duck.png, Discord uploads it to their servers as image.png). So you don't need to change the image.png part. However, if you are using a file that the specific extension matters, remember to change the image.png to the desired extension. An example of a file that requires a specific extension is a GIF so remember to change image.png to for example, an image.gifif you are using a GIF.

You can read more here at discord.py's official documentation: https://discordpy.readthedocs.io/en/latest/faq.html#how-do-i-use-a-local-image-file-for-an-embed-image

like image 56
Armster Avatar answered Dec 10 '22 10:12

Armster