From 1533fe588a243781892b459db78de13103126f42 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Wed, 11 Sep 2024 14:56:47 +0100 Subject: [PATCH] fix: webhooks not sending attachment info (#2513) * support multipart attachment info * noprint * fix logic * cl --------- Co-authored-by: Lala Sabathil --- CHANGELOG.md | 2 ++ discord/webhook/async_.py | 38 +++++++++++++++++++++----------------- 2 files changed, 23 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9fe6dd87b..0112d366c2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -54,6 +54,8 @@ These changes are available on the `master` branch, but have not yet been releas ([#2568](https://github.com/Pycord-Development/pycord/pull/2500)) - Fixed the `guild` attribute of `Member`s recieved from a `UserCommand` being `None`. ([#2573](https://github.com/Pycord-Development/pycord/pull/2573)) +- Fixed `Webhook.send` not including `Attachment` data. + ([#2513](https://github.com/Pycord-Development/pycord/pull/2513)) ## [2.6.0] - 2024-07-09 diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 6d8f7b35c5..090f7c96f2 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -644,8 +644,9 @@ def handle_message_parameters( payload["embeds"] = [] if embed is None else [embed.to_dict()] if content is not MISSING: payload["content"] = str(content) if content is not None else None + _attachments = [] if attachments is not MISSING: - payload["attachments"] = [a.to_dict() for a in attachments] + _attachments = [a.to_dict() for a in attachments] if view is not MISSING: payload["components"] = view.to_components() if view is not None else [] @@ -674,32 +675,35 @@ def handle_message_parameters( payload["allowed_mentions"] = previous_allowed_mentions.to_dict() multipart = [] + multipart_files = [] if file is not MISSING: files = [file] if files: - multipart.append({"name": "payload_json", "value": utils._to_json(payload)}) - payload = None - if len(files) == 1: - file = files[0] - multipart.append( + for index, file in enumerate(files): + multipart_files.append( { - "name": "file", + "name": f"files[{index}]", "value": file.fp, "filename": file.filename, "content_type": "application/octet-stream", } ) - else: - for index, file in enumerate(files): - multipart.append( - { - "name": f"file{index}", - "value": file.fp, - "filename": file.filename, - "content_type": "application/octet-stream", - } - ) + _attachments.append( + { + "id": index, + "filename": file.filename, + "description": file.description, + } + ) + + if _attachments: + payload["attachments"] = _attachments + + if multipart_files: + multipart.append({"name": "payload_json", "value": utils._to_json(payload)}) + payload = None + multipart += multipart_files return ExecuteWebhookParameters(payload=payload, multipart=multipart, files=files)