From 1fa5559f39f4de59328e55313bed9e76bc819ea8 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 4 Aug 2024 01:24:14 +0100 Subject: [PATCH 1/4] support multipart attachment info --- discord/webhook/async_.py | 39 ++++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 6d8f7b35c5..a7206b4fb1 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,36 @@ 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 + print(multipart) return ExecuteWebhookParameters(payload=payload, multipart=multipart, files=files) From 8c487401c638fca3d6d0dcb37b630c091e960ffa Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 4 Aug 2024 01:24:27 +0100 Subject: [PATCH 2/4] noprint --- discord/webhook/async_.py | 1 - 1 file changed, 1 deletion(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index a7206b4fb1..409ee94b49 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -704,7 +704,6 @@ def handle_message_parameters( multipart.append({"name": "payload_json", "value": utils._to_json(payload)}) payload = None multipart += multipart_files - print(multipart) return ExecuteWebhookParameters(payload=payload, multipart=multipart, files=files) From b3cbc7d986977af84d72e8fd7a412dcc254a6960 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Tue, 10 Sep 2024 20:16:10 +0100 Subject: [PATCH 3/4] fix logic --- discord/webhook/async_.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 409ee94b49..090f7c96f2 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -644,9 +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 = [] + _attachments = [] if attachments is not MISSING: - 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 [] @@ -689,7 +689,7 @@ def handle_message_parameters( "content_type": "application/octet-stream", } ) - attachments.append( + _attachments.append( { "id": index, "filename": file.filename, @@ -697,8 +697,8 @@ def handle_message_parameters( } ) - if attachments: - payload["attachments"] = attachments + if _attachments: + payload["attachments"] = _attachments if multipart_files: multipart.append({"name": "payload_json", "value": utils._to_json(payload)}) From 3dc71bc7c63f56adcbf435306f2ca96f5ca7ebae Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Tue, 10 Sep 2024 22:34:47 +0100 Subject: [PATCH 4/4] cl --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index c0be148b48..d283080661 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