Skip to content

feat: add thread_name field in the webhook field #1722

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 9 commits into from
Oct 4, 2024
6 changes: 5 additions & 1 deletion interactions/api/http/http_requests/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
"""
Expand All @@ -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}),
Expand Down
10 changes: 9 additions & 1 deletion interactions/models/discord/webhooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"]:
"""
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -256,6 +263,7 @@ async def send(
message_payload,
wait,
to_optional_snowflake(thread),
thread_name,
files=files or file,
)
if message_data:
Expand Down
Loading