Skip to content

Commit

Permalink
feat: add applied_tags parameter to Webhook.send (#2322)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
tyrantlink and Dorukyum committed Jan 22, 2024
1 parent 122cf46 commit 9422439
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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

Expand Down
18 changes: 17 additions & 1 deletion discord/webhook/async_.py
Expand Up @@ -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,
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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.
Expand All @@ -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:
Expand All @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down

0 comments on commit 9422439

Please sign in to comment.