disnake icon indicating copy to clipboard operation
disnake copied to clipboard

`disnake.Embed` methods supporting file param make the embed non-reusable

Open Enegg opened this issue 2 years ago • 1 comments

Summary

Embeds with attached files cannot be sent twice; the files are being closed after first upload, causing the second one to fail.

Reproduction Steps

  1. Create an Embed
  2. Add an image via .set_image(file=disnake.File(...))
  3. Send the embed in slash command response
  4. Edit the response message passing in the embed instance

Minimal Reproducible Code

No response

Expected Results

The embed should be reusable in places like message.edit / response.edit_original_message, possibly also for sending multiple messages.

Actual Results

Images set via .set_image(file=...) disappear after edit; on further attempt an exception is raised denoting IO operation on closed file:

Traceback (most recent call last):
  File "c:\...\disnake\disnake\ui\view.py", line 371, in _scheduled_task
    await item.callback(interaction)
  File "...\bot\app\extensions\item_lookup.py", line 56, in buff_button
    await inter.edit_original_message(embed=self.embed, view=self)
  File "...\disnake\disnake\interactions\base.py", line 478, in edit_original_message
    data = await adapter.edit_original_interaction_response(
  File "...\disnake\disnake\webhook\async_.py", line 173, in request
    async with session.request(
  File "...\bot\.venv\lib\site-packages\aiohttp\client.py", line 1138, in __aenter__
    self._resp = await self._coro
  File "...\bot\.venv\lib\site-packages\aiohttp\client.py", line 507, in _request
    req = self._request_class(
  File "...\bot\.venv\lib\site-packages\aiohttp\client_reqrep.py", line 313, in __init__
    self.update_body_from_data(data)
  File "...\bot\.venv\lib\site-packages\aiohttp\client_reqrep.py", line 507, in update_body_from_data
    body = body()
  File "...\bot\.venv\lib\site-packages\aiohttp\formdata.py", line 170, in __call__
    return self._gen_form_data()
  File "...\bot\.venv\lib\site-packages\aiohttp\formdata.py", line 163, in _gen_form_data
    self._writer.append_payload(part)
  File "...\bot\.venv\lib\site-packages\aiohttp\multipart.py", line 831, in append_payload
    size = payload.size
  File "...\bot\.venv\lib\site-packages\aiohttp\payload.py", line 369, in size
    position = self._value.tell()
ValueError: I/O operation on closed file.

Intents

guilds

System Information

- Python v3.10.1-final
- disnake v2.6.0-alpha
    - disnake pkg_resources: v2.6.0a4269+gd21ac843
- aiohttp v3.8.1
- system info: Windows 10 10.0.19044

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

https://canary.discord.com/channels/808030843078836254/913779868985090089/1020029386633789640

Enegg avatar Sep 15 '22 18:09 Enegg

Here's another conversation that could be useful to fix this bug https://discord.com/channels/808030843078836254/1021449537182777404/1021847974533402715

Snipy7374 avatar Sep 20 '22 20:09 Snipy7374

I shall take a look :)

Snipy7374 avatar Sep 29 '22 19:09 Snipy7374