From 50190e088e38257016e69b9b0004f17b814b4478 Mon Sep 17 00:00:00 2001 From: Andrin <65789180+Puncher1@users.noreply.github.com> Date: Tue, 12 Dec 2023 23:13:55 +0100 Subject: [PATCH] Add applied_tags param to Webhook.send --- discord/http.py | 7 +++++++ discord/webhook/async_.py | 14 +++++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/discord/http.py b/discord/http.py index 05d4b53ea..409a36cc9 100644 --- a/discord/http.py +++ b/discord/http.py @@ -153,6 +153,7 @@ def handle_message_parameters( mention_author: Optional[bool] = None, thread_name: str = MISSING, channel_payload: Dict[str, Any] = MISSING, + applied_tags: Optional[SnowflakeList] = MISSING, ) -> MultipartParameters: if files is not MISSING and file is not MISSING: raise TypeError('Cannot mix file and files keyword arguments.') @@ -243,6 +244,12 @@ def handle_message_parameters( payload['attachments'] = attachments_payload + if applied_tags is not MISSING: + if applied_tags is not None: + payload['applied_tags'] = applied_tags + else: + payload['applied_tags'] = [] + if channel_payload is not MISSING: payload = { 'message': payload, diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index 9ce18bbe4..2a9a649e5 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -45,7 +45,7 @@ from ..asset import Asset from ..partial_emoji import PartialEmoji from ..http import Route, handle_message_parameters, MultipartParameters, HTTPClient, json_or_text from ..mixins import Hashable -from ..channel import TextChannel, ForumChannel, PartialMessageable +from ..channel import TextChannel, ForumChannel, PartialMessageable, ForumTag from ..file import File __all__ = ( @@ -88,6 +88,7 @@ if TYPE_CHECKING: PartialChannel as PartialChannelPayload, ) from ..types.emoji import PartialEmoji as PartialEmojiPayload + from ..types.snowflake import SnowflakeList BE = TypeVar('BE', bound=BaseException) _State = Union[ConnectionState, '_WebhookState'] @@ -1639,6 +1640,7 @@ class Webhook(BaseWebhook): wait: bool = False, suppress_embeds: bool = False, silent: bool = False, + applied_tags: List[ForumTag] = MISSING, ) -> Optional[WebhookMessage]: """|coro| @@ -1724,6 +1726,10 @@ class Webhook(BaseWebhook): in the UI, but will not actually send a notification. .. versionadded:: 2.2 + applied_tags: List[:class:`ForumTag`] + Tags to apply to the thread if the webhook belongs to a :class:`~discord.ForumChannel`. + + .. versionadded:: 2.4 Raises -------- @@ -1782,6 +1788,11 @@ class Webhook(BaseWebhook): if thread_name is not MISSING and thread is not MISSING: raise TypeError('Cannot mix thread_name and thread keyword arguments.') + if applied_tags is MISSING: + applied_tag_ids = MISSING + else: + applied_tag_ids: SnowflakeList = [tag.id for tag in applied_tags] + with handle_message_parameters( content=content, username=username, @@ -1796,6 +1807,7 @@ class Webhook(BaseWebhook): thread_name=thread_name, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, + applied_tags=applied_tag_ids, ) as params: adapter = async_context.get() thread_id: Optional[int] = None