From 5b07e41a50feabf4a5a87f4bec62a3d6c6e53455 Mon Sep 17 00:00:00 2001 From: retr0-init <146389702+retr0-init@users.noreply.github.com> Date: Fri, 4 Oct 2024 05:58:45 +0100 Subject: [PATCH] feat: add `thread_name` field in the webhook field (#1722) * feat: add `thread_name` field in the webhook field * ci: correct from checks. * fixed: Add a missing comma * feat: check exclusive relationship between `thread` and `thread_name` * ci: correct from checks. --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- interactions/api/http/http_requests/webhooks.py | 6 +++++- interactions/models/discord/webhooks.py | 10 +++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/interactions/api/http/http_requests/webhooks.py b/interactions/api/http/http_requests/webhooks.py index f5b372c1c..1aa098a3b 100644 --- a/interactions/api/http/http_requests/webhooks.py +++ b/interactions/api/http/http_requests/webhooks.py @@ -126,6 +126,7 @@ async def execute_webhook( payload: dict, wait: bool = False, thread_id: "Snowflake_Type" = None, + thread_name: Optional[str] = None, files: list["UPLOADABLE_TYPE"] | None = None, ) -> Optional[discord_typings.MessageData]: """ @@ -136,13 +137,16 @@ async def execute_webhook( webhook_token: The token for the webhook payload: The JSON payload for the message wait: Waits for server confirmation of message send before response - thread_id: Send a message to the specified thread + thread_id: Send a message to the specified thread. Note that this cannot be used with `thread_name` + thread_name: Create a thread with this name. Note that this is only valid for forum channel and cannot be used with `thread_id` files: The files to send with this message Returns: The sent `message`, if `wait` is True else None """ + if thread_name is not None: + payload["thread_name"] = thread_name return await self.request( Route("POST", "/webhooks/{webhook_id}/{webhook_token}", webhook_id=webhook_id, webhook_token=webhook_token), params=dict_filter_none({"wait": "true" if wait else "false", "thread_id": thread_id}), diff --git a/interactions/models/discord/webhooks.py b/interactions/models/discord/webhooks.py index 548eaec9f..96a614b94 100644 --- a/interactions/models/discord/webhooks.py +++ b/interactions/models/discord/webhooks.py @@ -196,6 +196,7 @@ async def send( avatar_url: str | None = None, wait: bool = False, thread: "Snowflake_Type" = None, + thread_name: Optional[str] = None, **kwargs, ) -> Optional["Message"]: """ @@ -218,7 +219,8 @@ async def send( username: The username to use avatar_url: The url of an image to use as the avatar wait: Waits for confirmation of delivery. Set this to True if you intend to edit the message - thread: Send this webhook to a thread channel + thread: Send this webhook to a thread channel. Note that this cannot be used with `thread_name` set + thread_name: Create a thread with `thread_name` with this webhook. Note that this is only valid for forum channel and cannot be used with `thread` set Returns: New message object that was sent if `wait` is set to True @@ -230,6 +232,11 @@ async def send( if not content and not embeds and not embed and not files and not file and not stickers: raise EmptyMessageException("You cannot send a message without any content, embeds, files, or stickers") + if thread is not None and thread_name is not None: + raise ValueError( + "You cannot create a thread and send the message to another thread with a webhook at the same time!" + ) + if suppress_embeds: if isinstance(flags, int): flags = MessageFlags(flags) @@ -256,6 +263,7 @@ async def send( message_payload, wait, to_optional_snowflake(thread), + thread_name, files=files or file, ) if message_data: