Skip to content Skip to sidebar Skip to footer

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 ima

Solution 1:

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

Solution 2:

Peppa's answer is right, but I must add that if you are doing this for a gif, it is better to pass an actual url to set_image than the attachments://image.gif url. Because everytime you do the latter and call ctx.send or channel.send, the gif has to get uploaded first before being sent. This may take very long (around 2-3 minutes for a 5MB gif, for me) if your gif is not compressed. Whereas by passing a url you can get the gif in a matter of seconds.

Post a Comment for "Use A Local File As The Set_image File Discord.py"