From 9422439add9ac963ab8ac2cd7c222bbf934f88c8 Mon Sep 17 00:00:00 2001 From: tyrantlink <38902185+tyrantlink@users.noreply.github.com> Date: Mon, 22 Jan 2024 16:53:29 +0000 Subject: [PATCH] feat: add applied_tags parameter to Webhook.send (#2322) * added support for webhook applied_tags * update changelog * am a dummy forgot about half the typehinting * docs: fix versionadded * docs: update exception cases --------- Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- CHANGELOG.md | 2 ++ discord/webhook/async_.py | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index fea137c75a..207ed085ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -82,6 +82,8 @@ These changes are available on the `master` branch, but have not yet been releas - Added `default_reaction_emoji` parameter to `Guild.create_forum_channel()` and `ForumChannel.edit()` methods. ([#2178](https://github.com/Pycord-Development/pycord/pull/2178)) +- Added `applied_tags` parameter to `Webhook.send()` method. + ([#2322](https://github.com/Pycord-Development/pycord/pull/2322)) ### Changed diff --git a/discord/webhook/async_.py b/discord/webhook/async_.py index da001408ac..9c44c64d94 100644 --- a/discord/webhook/async_.py +++ b/discord/webhook/async_.py @@ -621,6 +621,7 @@ def handle_message_parameters( embed: Embed | None = MISSING, embeds: list[Embed] = MISSING, view: View | None = MISSING, + applied_tags: list[Snowflake] = MISSING, allowed_mentions: AllowedMentions | None = MISSING, previous_allowed_mentions: AllowedMentions | None = None, suppress: bool = False, @@ -654,6 +655,9 @@ def handle_message_parameters( flags = MessageFlags(suppress_embeds=suppress, ephemeral=ephemeral) payload["flags"] = flags.value + if applied_tags is not MISSING: + payload["applied_tags"] = applied_tags + if allowed_mentions: if previous_allowed_mentions is not None: payload["allowed_mentions"] = previous_allowed_mentions.merge( @@ -1566,6 +1570,7 @@ async def send( view: View = MISSING, thread: Snowflake = MISSING, thread_name: str | None = None, + applied_tags: list[Snowflake] = MISSING, wait: Literal[True], delete_after: float = None, ) -> WebhookMessage: @@ -1588,6 +1593,7 @@ async def send( view: View = MISSING, thread: Snowflake = MISSING, thread_name: str | None = None, + applied_tags: list[Snowflake] = MISSING, wait: Literal[False] = ..., delete_after: float = None, ) -> None: @@ -1609,6 +1615,7 @@ async def send( view: View = MISSING, thread: Snowflake = MISSING, thread_name: str | None = None, + applied_tags: list[Snowflake] = MISSING, wait: bool = False, delete_after: float = None, ) -> WebhookMessage | None: @@ -1680,6 +1687,10 @@ async def send( The name of the thread to create. Only works for forum channels. .. versionadded:: 2.0 + applied_tags: List[:class:`Snowflake`] + A list of tags to apply to the message. Only works for threads. + + .. versionadded:: 2.5 delete_after: :class:`float` If provided, the number of seconds to wait in the background before deleting the message we just sent. @@ -1704,7 +1715,8 @@ async def send( InvalidArgument Either there was no token associated with this webhook, ``ephemeral`` was passed with the improper webhook type, there was no state attached with this webhook when - giving it a view, or you specified both ``thread_name`` and ``thread``. + giving it a view, you specified both ``thread_name`` and ``thread``, or ``applied_tags`` + was passed with neither ``thread_name`` nor ``thread`` specified. """ if self.token is None: @@ -1721,6 +1733,9 @@ async def send( if thread and thread_name: raise InvalidArgument("You cannot specify both a thread and thread_name") + if applied_tags and not (thread or thread_name): + raise InvalidArgument("You cannot specify applied_tags without a thread") + application_webhook = self.type is WebhookType.application if ephemeral and not application_webhook: raise InvalidArgument( @@ -1749,6 +1764,7 @@ async def send( embeds=embeds, ephemeral=ephemeral, view=view, + applied_tags=applied_tags, allowed_mentions=allowed_mentions, previous_allowed_mentions=previous_mentions, )