docs: clarify disnake.Embed re-using disnake.File objects when editing messages#786
Conversation
|
Hmm, something I completely missed - Taking this as an example: a = await ctx.author.display_avatar.read()
e = disnake.Embed(title="embed")
e.set_image(file=disnake.File(io.BytesIO(a), filename="avatar.png"))
m = await ctx.send(embed=e)
await m.edit("hi", embed=e)The |
couldn't we introduce a new attribute |
|
|
|
thanks to @Enegg who helped me improve the code and delete some really shit that i wrote |
|
I feel like this could be fixed simply: document the error at runtime if the embed has any files attached that are not open, and then have a method which can clean the closed files. |
Right now this works (at least I haven't found any bug) so why we should change it |
onerandomusername
left a comment
There was a problem hiding this comment.
My biggest concern with this implement as it is is the amount of code and logic that is occuring in a finally of a try/except. If we could somehow minimize that, I would appreciate that.
That could be done by lazily clearing the files from an embed, but I'm also undecided on how this implementation works, it clears the files from an Embed object after they're sent.
However, most embed objects are only used once, so where this currently runs has a runtime impact on all embeds. I think I'd like to see it processed when an embed has a file when we attempt to send it, rather than after the embed is sent.
shiftinv
left a comment
There was a problem hiding this comment.
The docs of Embed.set_image and .set_thumbnail should mention that reusing embeds with files won't work in most cases (not sure on the wording).
looks good to me otherwise
@shiftinv |
@Snipy7374 There are a couple cases where it doesn't work, e.g. sending the same embed object in two separate messages; afaict they can only be reused as long as you're editing the same message the embed was sent in originally, right? |
@shiftinv This is true, I had not thought about it. However while I was testing what you said I found a bug, using the same embed object, changing files and editing a message you get an I/O error message on closed file. reproducible code: e = disnake.Embed()
e.set_image(file=disnake.File("..."))
e.set_thumbnail(file=disnake.File("..."))
await inter.response.send_message(embed=e)
e.set_image(file=disnake.File(...))
e.set_thumbnail(file=disnake.File(...))
await inter.edit_original_message(embed=e)
await inter.send(embed=e)This is because we have to clear |
|
https://canary.discord.com/channels/808030843078836254/913779868985090089/1035407513908154378 at the end we decided to just make a docs change |
disnake.Embed re-using disnake.File objects when editing messagesdisnake.Embed re-using disnake.File objects when editing messages
Co-authored-by: shiftinv <8530778+shiftinv@users.noreply.github.com> Signed-off-by: Snipy7374 <davidecucci07@gmail.com>
Co-authored-by: shiftinv <8530778+shiftinv@users.noreply.github.com> Signed-off-by: Snipy7374 <davidecucci07@gmail.com>
Co-authored-by: shiftinv <8530778+shiftinv@users.noreply.github.com> Signed-off-by: Snipy7374 <davidecucci07@gmail.com>
Summary
disnake.Embedmethods supporting file param make the embed non-reusable #748Checklist
task linttask pyright