Skip to content

fix: 🐛 TypeError when specifying thread_name in Webhook.send #2761

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

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,9 @@ These changes are available on the `master` branch, but have not yet been releas
- Fixed `ForumChannel.edit` allowing `default_reaction_emoji` to be `None`.
([#2739](https://github.com/Pycord-Development/pycord/pull/2739))
- Fixed missing `None` type hints in `Select.__init__`.
([#2746](https://github.com/Pycord-Development/pycord/pull/2746))
([#2746])(https://github.com/Pycord-Development/pycord/pull/2746)
- Fixed `TypeError` when specifying `thread_name` in `Webhook.send`.
([#2761])(https://github.com/Pycord-Development/pycord/pull/2761)
- Updated `valid_locales` to support `in` and `es-419`.
([#2767](https://github.com/Pycord-Development/pycord/pull/2767))
- Fixed `Webhook.edit` not working with `attachments=[]`.
Expand Down
10 changes: 5 additions & 5 deletions discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -337,16 +337,12 @@ def execute_webhook(
multipart: list[dict[str, Any]] | None = None,
files: list[File] | None = None,
thread_id: int | None = None,
thread_name: str | None = None,
wait: bool = False,
) -> Response[MessagePayload | None]:
params = {"wait": int(wait)}
if thread_id:
params["thread_id"] = thread_id

if thread_name:
payload["thread_name"] = thread_name

route = Route(
"POST",
"/webhooks/{webhook_id}/{webhook_token}",
Expand Down Expand Up @@ -633,6 +629,7 @@ def handle_message_parameters(
allowed_mentions: AllowedMentions | None = MISSING,
previous_allowed_mentions: AllowedMentions | None = None,
suppress: bool = False,
thread_name: str | None = None,
) -> ExecuteWebhookParameters:
if files is not MISSING and file is not MISSING:
raise TypeError("Cannot mix file and files keyword arguments.")
Expand Down Expand Up @@ -717,6 +714,9 @@ def handle_message_parameters(

payload["flags"] = flags.value

if thread_name:
payload["thread_name"] = thread_name

if multipart_files:
multipart.append({"name": "payload_json", "value": utils._to_json(payload)})
payload = None
Expand Down Expand Up @@ -1808,6 +1808,7 @@ async def send(
applied_tags=applied_tags,
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
thread_name=thread_name,
)
adapter = async_context.get()
thread_id: int | None = None
Expand All @@ -1824,7 +1825,6 @@ async def send(
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
thread_name=thread_name,
wait=wait,
)

Expand Down
6 changes: 1 addition & 5 deletions discord/webhook/sync.py
Original file line number Diff line number Diff line change
Expand Up @@ -307,16 +307,12 @@ def execute_webhook(
multipart: list[dict[str, Any]] | None = None,
files: list[File] | None = None,
thread_id: int | None = None,
thread_name: str | None = None,
wait: bool = False,
):
params = {"wait": int(wait)}
if thread_id:
params["thread_id"] = thread_id

if thread_name:
payload["thread_name"] = thread_name

route = Route(
"POST",
"/webhooks/{webhook_id}/{webhook_token}",
Expand Down Expand Up @@ -1080,6 +1076,7 @@ def send(
allowed_mentions=allowed_mentions,
previous_allowed_mentions=previous_mentions,
suppress=suppress,
thread_name=thread_name,
)
adapter: WebhookAdapter = _get_webhook_adapter()
thread_id: int | None = None
Expand All @@ -1094,7 +1091,6 @@ def send(
multipart=params.multipart,
files=params.files,
thread_id=thread_id,
thread_name=thread_name,
wait=wait,
)
if wait:
Expand Down