Skip to content

Commit 5b07e41

Browse files
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>
1 parent b030d65 commit 5b07e41

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

interactions/api/http/http_requests/webhooks.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ async def execute_webhook(
126126
payload: dict,
127127
wait: bool = False,
128128
thread_id: "Snowflake_Type" = None,
129+
thread_name: Optional[str] = None,
129130
files: list["UPLOADABLE_TYPE"] | None = None,
130131
) -> Optional[discord_typings.MessageData]:
131132
"""
@@ -136,13 +137,16 @@ async def execute_webhook(
136137
webhook_token: The token for the webhook
137138
payload: The JSON payload for the message
138139
wait: Waits for server confirmation of message send before response
139-
thread_id: Send a message to the specified thread
140+
thread_id: Send a message to the specified thread. Note that this cannot be used with `thread_name`
141+
thread_name: Create a thread with this name. Note that this is only valid for forum channel and cannot be used with `thread_id`
140142
files: The files to send with this message
141143
142144
Returns:
143145
The sent `message`, if `wait` is True else None
144146
145147
"""
148+
if thread_name is not None:
149+
payload["thread_name"] = thread_name
146150
return await self.request(
147151
Route("POST", "/webhooks/{webhook_id}/{webhook_token}", webhook_id=webhook_id, webhook_token=webhook_token),
148152
params=dict_filter_none({"wait": "true" if wait else "false", "thread_id": thread_id}),

interactions/models/discord/webhooks.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,6 +196,7 @@ async def send(
196196
avatar_url: str | None = None,
197197
wait: bool = False,
198198
thread: "Snowflake_Type" = None,
199+
thread_name: Optional[str] = None,
199200
**kwargs,
200201
) -> Optional["Message"]:
201202
"""
@@ -218,7 +219,8 @@ async def send(
218219
username: The username to use
219220
avatar_url: The url of an image to use as the avatar
220221
wait: Waits for confirmation of delivery. Set this to True if you intend to edit the message
221-
thread: Send this webhook to a thread channel
222+
thread: Send this webhook to a thread channel. Note that this cannot be used with `thread_name` set
223+
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
222224
223225
Returns:
224226
New message object that was sent if `wait` is set to True
@@ -230,6 +232,11 @@ async def send(
230232
if not content and not embeds and not embed and not files and not file and not stickers:
231233
raise EmptyMessageException("You cannot send a message without any content, embeds, files, or stickers")
232234

235+
if thread is not None and thread_name is not None:
236+
raise ValueError(
237+
"You cannot create a thread and send the message to another thread with a webhook at the same time!"
238+
)
239+
233240
if suppress_embeds:
234241
if isinstance(flags, int):
235242
flags = MessageFlags(flags)
@@ -256,6 +263,7 @@ async def send(
256263
message_payload,
257264
wait,
258265
to_optional_snowflake(thread),
266+
thread_name,
259267
files=files or file,
260268
)
261269
if message_data:

0 commit comments

Comments
 (0)