diff --git a/changelog/1085.feature.rst b/changelog/1085.feature.rst new file mode 100644 index 0000000000..f2dd477bca --- /dev/null +++ b/changelog/1085.feature.rst @@ -0,0 +1 @@ +Add ``applied_tags`` parameter to :meth:`Webhook.send`. diff --git a/disnake/webhook/async_.py b/disnake/webhook/async_.py index 851a88dfee..5c252d9663 100644 --- a/disnake/webhook/async_.py +++ b/disnake/webhook/async_.py @@ -492,7 +492,9 @@ def handle_message_parameters_dict( allowed_mentions: Optional[AllowedMentions] = MISSING, previous_allowed_mentions: Optional[AllowedMentions] = None, stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING, - thread_name: Optional[str] = None, + # these parameters are exclusive to webhooks in forum channels + thread_name: str = MISSING, + applied_tags: Sequence[Snowflake] = MISSING, ) -> DictPayloadParameters: if files is not MISSING and file is not MISSING: raise TypeError("Cannot mix file and files keyword arguments.") @@ -554,8 +556,10 @@ def handle_message_parameters_dict( if stickers is not MISSING: payload["sticker_ids"] = [s.id for s in stickers] - if thread_name is not None: + if thread_name: payload["thread_name"] = thread_name + if applied_tags: + payload["applied_tags"] = [t.id for t in applied_tags] return DictPayloadParameters(payload=payload, files=files) @@ -579,7 +583,9 @@ def handle_message_parameters( allowed_mentions: Optional[AllowedMentions] = MISSING, previous_allowed_mentions: Optional[AllowedMentions] = None, stickers: Sequence[Union[GuildSticker, StandardSticker, StickerItem]] = MISSING, - thread_name: Optional[str] = None, + # these parameters are exclusive to webhooks in forum channels + thread_name: str = MISSING, + applied_tags: Sequence[Snowflake] = MISSING, ) -> PayloadParameters: params = handle_message_parameters_dict( content=content, @@ -600,6 +606,7 @@ def handle_message_parameters( previous_allowed_mentions=previous_allowed_mentions, stickers=stickers, thread_name=thread_name, + applied_tags=applied_tags, ) if params.files: @@ -1451,6 +1458,7 @@ async def send( components: Components[MessageUIComponent] = ..., thread: Snowflake = ..., thread_name: str = ..., + applied_tags: Sequence[Snowflake] = ..., wait: Literal[True], delete_after: float = ..., ) -> WebhookMessage: @@ -1476,6 +1484,7 @@ async def send( components: Components[MessageUIComponent] = ..., thread: Snowflake = ..., thread_name: str = ..., + applied_tags: Sequence[Snowflake] = ..., wait: Literal[False] = ..., delete_after: float = ..., ) -> None: @@ -1499,7 +1508,8 @@ async def send( view: View = MISSING, components: Components[MessageUIComponent] = MISSING, thread: Snowflake = MISSING, - thread_name: Optional[str] = None, + thread_name: str = MISSING, + applied_tags: Sequence[Snowflake] = MISSING, wait: bool = False, delete_after: float = MISSING, ) -> Optional[WebhookMessage]: @@ -1516,6 +1526,10 @@ async def send( it must be a rich embed type. You cannot mix the ``embed`` parameter with the ``embeds`` parameter, which must be a :class:`list` of :class:`Embed` objects to send. + To send a message in a thread, provide the ``thread`` parameter. + If this webhook is in a :class:`ForumChannel`, the ``thread_name`` parameter can + be used to create a new thread instead (optionally with ``applied_tags``). + .. versionchanged:: 2.6 Raises :exc:`WebhookTokenMissing` instead of ``InvalidArgument``. @@ -1587,6 +1601,11 @@ async def send( representing the created thread, may be a :class:`PartialMessageable`. .. versionadded:: 2.6 + applied_tags: Sequence[:class:`abc.Snowflake`] + If in a forum channel and creating a new thread (see ``thread_name`` above), + the tags to apply to the new thread. Maximum of 5. + + .. versionadded:: 2.10 wait: :class:`bool` Whether the server should wait before sending a response. This essentially @@ -1632,7 +1651,7 @@ async def send( You specified both ``embed`` and ``embeds`` or ``file`` and ``files``. ``ephemeral`` was passed with the improper webhook type. There was no state attached with this webhook when giving it a view. - Both ``thread`` and ``thread_name`` were provided. + Both ``thread`` and ``thread_name``/``applied_tags`` were provided. WebhookTokenMissing There was no token associated with this webhook. ValueError @@ -1666,9 +1685,11 @@ async def send( view.timeout = 15 * 60.0 thread_id: Optional[int] = None - if thread is not MISSING and thread_name is not None: - raise TypeError("only one of thread and thread_name can be provided.") - elif thread is not MISSING: + if thread is not MISSING: + if thread_name or applied_tags: + raise TypeError( + "Cannot use `thread_name` or `applied_tags` when `thread` is provided." + ) thread_id = thread.id params = handle_message_parameters( @@ -1686,6 +1707,7 @@ async def send( view=view, components=components, thread_name=thread_name, + applied_tags=applied_tags, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, ) diff --git a/disnake/webhook/sync.py b/disnake/webhook/sync.py index b1debb9cf3..2f8e9d7377 100644 --- a/disnake/webhook/sync.py +++ b/disnake/webhook/sync.py @@ -13,7 +13,19 @@ import threading import time from errno import ECONNRESET -from typing import TYPE_CHECKING, Any, Dict, List, Literal, Optional, Tuple, Type, Union, overload +from typing import ( + TYPE_CHECKING, + Any, + Dict, + List, + Literal, + Optional, + Sequence, + Tuple, + Type, + Union, + overload, +) from urllib.parse import quote as urlquote from .. import utils @@ -872,6 +884,7 @@ def send( allowed_mentions: AllowedMentions = ..., thread: Snowflake = ..., thread_name: str = ..., + applied_tags: Sequence[Snowflake] = ..., wait: Literal[True], ) -> SyncWebhookMessage: ... @@ -893,6 +906,7 @@ def send( allowed_mentions: AllowedMentions = ..., thread: Snowflake = ..., thread_name: str = ..., + applied_tags: Sequence[Snowflake] = ..., wait: Literal[False] = ..., ) -> None: ... @@ -912,7 +926,8 @@ def send( flags: MessageFlags = MISSING, allowed_mentions: AllowedMentions = MISSING, thread: Snowflake = MISSING, - thread_name: Optional[str] = None, + thread_name: str = MISSING, + applied_tags: Sequence[Snowflake] = MISSING, wait: bool = False, ) -> Optional[SyncWebhookMessage]: """Sends a message using the webhook. @@ -926,6 +941,10 @@ def send( it must be a rich embed type. You cannot mix the ``embed`` parameter with the ``embeds`` parameter, which must be a :class:`list` of :class:`Embed` objects to send. + To send a message in a thread, provide the ``thread`` parameter. + If this webhook is in a :class:`ForumChannel`, the ``thread_name`` parameter can + be used to create a new thread instead (optionally with ``applied_tags``). + .. versionchanged:: 2.6 Raises :exc:`WebhookTokenMissing` instead of ``InvalidArgument``. @@ -963,11 +982,17 @@ def send( .. versionadded:: 2.0 thread_name: :class:`str` - If in a forum channel, and thread is not specified, + If in a forum channel, and ``thread`` is not specified, the name of the newly created thread. .. versionadded:: 2.6 + applied_tags: Sequence[:class:`abc.Snowflake`] + If in a forum channel and creating a new thread (see ``thread_name`` above), + the tags to apply to the new thread. Maximum of 5. + + .. versionadded:: 2.10 + suppress_embeds: :class:`bool` Whether to suppress embeds for the message. This hides all the embeds from the UI if set to ``True``. @@ -999,7 +1024,7 @@ def send( The authorization token for the webhook is incorrect. TypeError You specified both ``embed`` and ``embeds`` or ``file`` and ``files``, - or both ``thread`` and ``thread_name`` were provided. + or both ``thread`` and ``thread_name``/``applied_tags`` were provided. ValueError The length of ``embeds`` was invalid @@ -1021,9 +1046,11 @@ def send( content = MISSING thread_id: Optional[int] = None - if thread is not MISSING and thread_name is not None: - raise TypeError("only one of thread and thread_name can be provided.") - elif thread is not MISSING: + if thread is not MISSING: + if thread_name or applied_tags: + raise TypeError( + "Cannot use `thread_name` or `applied_tags` when `thread` is provided." + ) thread_id = thread.id params = handle_message_parameters( @@ -1038,6 +1065,7 @@ def send( embed=embed, embeds=embeds, thread_name=thread_name, + applied_tags=applied_tags, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, )