Skip to content

Commit 5bb7845

Browse files
NeloBlivionLulalaby
authored andcommitted
fix: webhooks not sending attachment info (Pycord-Development#2513)
* support multipart attachment info * noprint * fix logic * cl --------- Co-authored-by: Lala Sabathil <[email protected]>
1 parent ccde0f9 commit 5bb7845

File tree

2 files changed

+23
-17
lines changed

2 files changed

+23
-17
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ These changes are available on the `master` branch, but have not yet been releas
5454
([#2568](https://github.com/Pycord-Development/pycord/pull/2500))
5555
- Fixed the `guild` attribute of `Member`s recieved from a `UserCommand` being `None`.
5656
([#2573](https://github.com/Pycord-Development/pycord/pull/2573))
57+
- Fixed `Webhook.send` not including `Attachment` data.
58+
([#2513](https://github.com/Pycord-Development/pycord/pull/2513))
5759

5860
## [2.6.0] - 2024-07-09
5961

discord/webhook/async_.py

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -644,8 +644,9 @@ def handle_message_parameters(
644644
payload["embeds"] = [] if embed is None else [embed.to_dict()]
645645
if content is not MISSING:
646646
payload["content"] = str(content) if content is not None else None
647+
_attachments = []
647648
if attachments is not MISSING:
648-
payload["attachments"] = [a.to_dict() for a in attachments]
649+
_attachments = [a.to_dict() for a in attachments]
649650

650651
if view is not MISSING:
651652
payload["components"] = view.to_components() if view is not None else []
@@ -674,32 +675,35 @@ def handle_message_parameters(
674675
payload["allowed_mentions"] = previous_allowed_mentions.to_dict()
675676

676677
multipart = []
678+
multipart_files = []
677679
if file is not MISSING:
678680
files = [file]
679681

680682
if files:
681-
multipart.append({"name": "payload_json", "value": utils._to_json(payload)})
682-
payload = None
683-
if len(files) == 1:
684-
file = files[0]
685-
multipart.append(
683+
for index, file in enumerate(files):
684+
multipart_files.append(
686685
{
687-
"name": "file",
686+
"name": f"files[{index}]",
688687
"value": file.fp,
689688
"filename": file.filename,
690689
"content_type": "application/octet-stream",
691690
}
692691
)
693-
else:
694-
for index, file in enumerate(files):
695-
multipart.append(
696-
{
697-
"name": f"file{index}",
698-
"value": file.fp,
699-
"filename": file.filename,
700-
"content_type": "application/octet-stream",
701-
}
702-
)
692+
_attachments.append(
693+
{
694+
"id": index,
695+
"filename": file.filename,
696+
"description": file.description,
697+
}
698+
)
699+
700+
if _attachments:
701+
payload["attachments"] = _attachments
702+
703+
if multipart_files:
704+
multipart.append({"name": "payload_json", "value": utils._to_json(payload)})
705+
payload = None
706+
multipart += multipart_files
703707

704708
return ExecuteWebhookParameters(payload=payload, multipart=multipart, files=files)
705709

0 commit comments

Comments
 (0)