Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: webhooks not sending attachment info #2513

Merged
merged 8 commits into from
Sep 11, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 21 additions & 17 deletions discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved
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 []
Expand Down Expand Up @@ -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)

Expand Down
Loading