# Buggy code
def execute_webhook(self, *, payload, wait=False, file=None, files=None):
    if file is not None:
        multipart = {"file": file, "payload_json": utils.to_json(payload)}
        data = None
    elif files is not None:
        multipart = {"payload_json": utils.to_json(payload)}
        for i, file in enumerate(files, start=1):
            multipart["file%i" % i] = file
        data = None
    else:
        data = payload
        multipart = None

    url = "%s?wait=%d" % (self._request_url, wait)
    maybe_coro = self.request("POST", url, multipart=multipart, payload=data)
    return self.handle_execution_response(maybe_coro, wait=wait)


# Traceback (ValueError)
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/discord/ext/commands/core.py", line 62, in wrapped
ret = await coro(*args, **kwargs)
File "/home/fedora/Thanatos/modules/test.py", line 9, in test
await webhook.send(file=discord.File("file.txt"))
File "/usr/local/lib/python3.7/site-packages/discord/webhook.py", line 194, in handle_execution_response
data = await response
File "/usr/local/lib/python3.7/site-packages/discord/webhook.py", line 162, in request
async with self.session.request(verb, url, headers=headers, data=data) as r:
File "/usr/local/lib64/python3.7/site-packages/aiohttp/client.py", line 855, in __aenter__
self._resp = await self._coro
File "/usr/local/lib64/python3.7/site-packages/aiohttp/client.py", line 361, in _request
ssl=ssl, proxy_headers=proxy_headers, traces=traces)
File "/usr/local/lib64/python3.7/site-packages/aiohttp/client_reqrep.py", line 233, in __init__
self.update_body_from_data(data)
File "/usr/local/lib64/python3.7/site-packages/aiohttp/client_reqrep.py", line 405, in update_body_from_data
body = body()
File "/usr/local/lib64/python3.7/site-packages/aiohttp/formdata.py", line 141, in __call__
return self._gen_form_data()
File "/usr/local/lib64/python3.7/site-packages/aiohttp/formdata.py", line 135, in _gen_form_data
self._writer.append_payload(part)
File "/usr/local/lib64/python3.7/site-packages/aiohttp/multipart.py", line 745, in append_payload
size = payload.size
File "/usr/local/lib64/python3.7/site-packages/aiohttp/payload.py", line 284, in size
return os.fstat(self._value.fileno()).st_size - self._value.tell()
ValueError: I/O operation on closed file

# Fixed code
def execute_webhook(self, *, payload, wait=False, file=None, files=None):
    cleanup = None
    if file is not None:
        multipart = {
            "file": (file.filename, file.open_file(), "application/octet-stream"),
            "payload_json": utils.to_json(payload),
        }
        data = None
        cleanup = file.close
    elif files is not None:
        multipart = {"payload_json": utils.to_json(payload)}
        for i, file in enumerate(files, start=1):
            multipart["file%i" % i] = (
                file.filename,
                file.open_file(),
                "application/octet-stream",
            )
        data = None

        def _anon():
            for f in files:
                f.close()

        cleanup = _anon
    else:
        data = payload
        multipart = None

    url = "%s?wait=%d" % (self._request_url, wait)
    try:
        maybe_coro = self.request("POST", url, multipart=multipart, payload=data)
    finally:
        if cleanup is not None:
            if not asyncio.iscoroutine(maybe_coro):
                cleanup()
            else:
                maybe_coro = self._wrap_coroutine_and_cleanup(maybe_coro, cleanup)
    return self.handle_execution_response(maybe_coro, wait=wait)