Skip to content

Commit

Permalink
Add applied_tags param to Webhook.send
Browse files Browse the repository at this point in the history
  • Loading branch information
Puncher1 committed Dec 12, 2023
1 parent f6182e5 commit 50190e0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
7 changes: 7 additions & 0 deletions discord/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.')
Expand Down Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion discord/webhook/async_.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
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__ = (
Expand Down Expand Up @@ -88,6 +88,7 @@
PartialChannel as PartialChannelPayload,
)
from ..types.emoji import PartialEmoji as PartialEmojiPayload
from ..types.snowflake import SnowflakeList

BE = TypeVar('BE', bound=BaseException)
_State = Union[ConnectionState, '_WebhookState']
Expand Down Expand Up @@ -1639,6 +1640,7 @@ async def send(
wait: bool = False,
suppress_embeds: bool = False,
silent: bool = False,
applied_tags: List[ForumTag] = MISSING,
) -> Optional[WebhookMessage]:
"""|coro|
Expand Down Expand Up @@ -1724,6 +1726,10 @@ async def send(
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
--------
Expand Down Expand Up @@ -1782,6 +1788,11 @@ async def send(
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,
Expand All @@ -1796,6 +1807,7 @@ async def send(
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
Expand Down

0 comments on commit 50190e0

Please sign in to comment.