Thanks to discord.py, sending local files as embed images is simple. You have to create an instance of
When using the file-like object, you have to open it in
# When you know the file exact path, you can pass it. file = discord.File("/this/is/path/to/my/file.png", filename="file.png") # When you have the file-like object, then you can pass this instead path. with open("/this/is/path/to/my/file.png", "rb") as f: file = discord.File(f)
rb('read binary') mode. Also, in this case, passing
filenameto it is not necessary. Please note that
filenamemust not contain underscores. This is a Discord limitation.
After this, you can send an embed with an attachment to Discord:
embed = discord.Embed() # Set other fields embed.set_image(url="attachment://file.png") # Filename here must be exactly same as attachment filename.
This example uses
await channel.send(file=file, embed=embed)
discord.TextChannelfor sending, but any instance of
discord.abc.Messageablecan be used for sending.