#embed.set_image(url=image) where image is a PIL.Image
1 messages · Page 1 of 1 (latest)
I think that’s a discord limitation since it only takes a url
Should I just create some private server where my bot can send the image first, and then grab that url for embed.set_image(url=..)
that should work
set the embed image to attachment://{filename} and then send the file in the message
?tag localfile
f = discord.File("some_file_path", filename="image.png")
e = discord.Embed()
e.set_image(url="attachment://image.png")
await messagable.send(file=f, embed=e)```
"some_file_path" can also be a Bytes object, which you probably have when working with PIL
@languid wedge Does this work without sending file=f in the message?
I tried it with and without sending the file, and it doesn't add the image to the embed when I don't send the file
you have to use file
So there's no way this code would work if I changed the last line to await messagable.send(embed=e) (removing file=f)
This code works
But I will just have a bytes file sent as well as the embed
and I don't want the byes file being sent as it clutters the channel
you misunderstand
that snippet is (equivalent to) discord's official solution to embedding an upload in an image
it will show up inside the embed instead of separately
I got it to work now thanks Nelo!
im trying to pass the file path as a BytesIO object, it doesnt show any errors, but it doesnt show the image in the embed
i tried sending a bytes array, but it shows and error
that's what xp_bar returns
dont know why, but i got it working using img_byte_arr.seek(0)
If it helps, here's what worked for me:
image = Image.open(background_image)
arr = io.BytesIO()
image.save(arr, format='PNG')
arr.seek(0)
f = discord.File(arr, filename="image.png")
return file=f, url="attachment://image.png"