diff --git a/discord/http.py b/discord/http.py index 8ae8aedd9..8ca579da8 100644 --- a/discord/http.py +++ b/discord/http.py @@ -171,6 +171,7 @@ def handle_message_parameters( stickers: Optional[SnowflakeList] = MISSING, previous_allowed_mentions: Optional[AllowedMentions] = None, mention_author: Optional[bool] = None, + thread_name: str = MISSING, channel_payload: Dict[str, Any] = MISSING, ) -> MultipartParameters: if files is not MISSING and file is not MISSING: @@ -224,6 +225,9 @@ def handle_message_parameters( if flags is not MISSING: payload['flags'] = flags.value + if thread_name is not MISSING: + payload['thread_name'] = thread_name + if allowed_mentions: if previous_allowed_mentions is not None: payload['allowed_mentions'] = previous_allowed_mentions.merge(allowed_mentions).to_dict() diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 23e8fe7c7..35b5ce0da 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -1300,6 +1300,7 @@ class Webhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: Literal[True], suppress_embeds: bool = MISSING, ) -> WebhookMessage: @@ -1319,6 +1320,7 @@ class Webhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: Literal[False] = ..., suppress_embeds: bool = MISSING, ) -> None: @@ -1337,6 +1339,7 @@ class Webhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: bool = False, suppress_embeds: bool = False, ) -> Optional[WebhookMessage]: @@ -1393,6 +1396,13 @@ class Webhook(BaseWebhook): thread: :class:`~discord.abc.Snowflake` The thread to send this webhook to. + .. versionadded:: 2.0 + thread_name: :class:`str` + The thread name to create with this webhook if the webhook belongs + to a :class:`~discord.ForumChannel`. Note that this is mutually + exclusive with the ``thread`` parameter, as this will create a + new thread with the given name. + .. versionadded:: 2.0 suppress_embeds: :class:`bool` Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. @@ -1408,7 +1418,8 @@ class Webhook(BaseWebhook): Forbidden The authorization token for the webhook is incorrect. TypeError - You specified both ``embed`` and ``embeds`` or ``file`` and ``files``. + You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` + or ``thread`` and ``thread_name``. ValueError The length of ``embeds`` was invalid, or there was no token associated with this webhook. @@ -1434,6 +1445,9 @@ class Webhook(BaseWebhook): if self.type is WebhookType.application: wait = True + if thread_name is not MISSING and thread is not MISSING: + raise TypeError('Cannot mix thread_name and thread keyword arguments.') + params = handle_message_parameters( content=content, username=username, @@ -1444,6 +1458,7 @@ class Webhook(BaseWebhook): embed=embed, embeds=embeds, flags=flags, + thread_name=thread_name, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, ) diff --git a/discord/webhook/sync.py b/discord/webhook/sync.py index 55bfa82d6..7592bcf60 100644 --- a/discord/webhook/sync.py +++ b/discord/webhook/sync.py @@ -863,6 +863,7 @@ class SyncWebhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: Literal[True], suppress_embeds: bool = MISSING, ) -> SyncWebhookMessage: @@ -882,6 +883,7 @@ class SyncWebhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: Literal[False] = ..., suppress_embeds: bool = MISSING, ) -> None: @@ -900,6 +902,7 @@ class SyncWebhook(BaseWebhook): embeds: Sequence[Embed] = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, + thread_name: str = MISSING, wait: bool = False, suppress_embeds: bool = False, ) -> Optional[SyncWebhookMessage]: @@ -949,6 +952,13 @@ class SyncWebhook(BaseWebhook): thread: :class:`~discord.abc.Snowflake` The thread to send this message to. + .. versionadded:: 2.0 + thread_name: :class:`str` + The thread name to create with this webhook if the webhook belongs + to a :class:`~discord.ForumChannel`. Note that this is mutually + exclusive with the ``thread`` parameter, as this will create a + new thread with the given name. + .. versionadded:: 2.0 suppress_embeds: :class:`bool` Whether to suppress embeds for the message. This sends the message without any embeds if set to ``True``. @@ -965,6 +975,7 @@ class SyncWebhook(BaseWebhook): The authorization token for the webhook is incorrect. TypeError You specified both ``embed`` and ``embeds`` or ``file`` and ``files`` + or ``thread`` and ``thread_name``. ValueError The length of ``embeds`` was invalid or there was no token associated with this webhook. @@ -987,6 +998,9 @@ class SyncWebhook(BaseWebhook): else: flags = MISSING + if thread_name is not MISSING and thread is not MISSING: + raise TypeError('Cannot mix thread_name and thread keyword arguments.') + params = handle_message_parameters( content=content, username=username, @@ -996,6 +1010,7 @@ class SyncWebhook(BaseWebhook): files=files, embed=embed, embeds=embeds, + thread_name=thread_name, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, flags=flags,