From a20e3cdee2dee85b3f354eaa5d599f14388ef587 Mon Sep 17 00:00:00 2001 From: Soheab_ <33902984+Soheab@users.noreply.github.com> Date: Sun, 9 Feb 2025 16:51:36 +0100 Subject: [PATCH] Add support for soundboard_sounds field on message --- discord/message.py | 17 ++++++++++++++++- discord/types/message.py | 2 ++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/discord/message.py b/discord/message.py index 3016d2f29..2b04bd7c7 100644 --- a/discord/message.py +++ b/discord/message.py @@ -65,6 +65,7 @@ from .sticker import StickerItem, GuildSticker from .threads import Thread from .channel import PartialMessageable from .poll import Poll +from .soundboard import SoundboardSound, SoundboardDefaultSound if TYPE_CHECKING: from typing_extensions import Self @@ -81,6 +82,7 @@ if TYPE_CHECKING: CallMessage as CallMessagePayload, PurchaseNotificationResponse as PurchaseNotificationResponsePayload, GuildProductPurchase as GuildProductPurchasePayload, + SoundboardSound as SoundboardSoundPayload, ) from .types.interactions import MessageInteraction as MessageInteractionPayload @@ -2158,6 +2160,7 @@ class Message(PartialMessage, Hashable): 'call', 'purchase_notification', 'message_snapshots', + 'soundboard_sounds', ) if TYPE_CHECKING: @@ -2197,6 +2200,7 @@ class Message(PartialMessage, Hashable): self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') self.stickers: List[StickerItem] = [StickerItem(data=d, state=state) for d in data.get('sticker_items', [])] self.message_snapshots: List[MessageSnapshot] = MessageSnapshot._from_value(state, data.get('message_snapshots')) + self.soundboard_sounds: List[Union[SoundboardSound, SoundboardDefaultSound]] = [] self.poll: Optional[Poll] = None try: @@ -2299,7 +2303,7 @@ class Message(PartialMessage, Hashable): else: self.purchase_notification = PurchaseNotification(purchase_notification) - for handler in ('author', 'member', 'mentions', 'mention_roles', 'components', 'call'): + for handler in ('author', 'member', 'mentions', 'mention_roles', 'components', 'call', 'soundboard_sounds'): try: getattr(self, f'_handle_{handler}')(data[handler]) except KeyError: @@ -2492,6 +2496,17 @@ class Message(PartialMessage, Hashable): else: self.call = None + def _handle_soundboard_sounds(self, data: List[SoundboardSoundPayload]): + for sound in data: + guild = self._state._get_guild(utils._get_as_snowflake(sound, 'guild_id')) + try: + if guild: + self.soundboard_sounds.append(SoundboardSound(state=self._state, data=sound, guild=guild)) + else: + self.soundboard_sounds.append(SoundboardDefaultSound(state=self._state, data=sound)) # type: ignore + except KeyError: + pass + def _rebind_cached_references( self, new_guild: Guild, diff --git a/discord/types/message.py b/discord/types/message.py index ae38db46f..499cba4fb 100644 --- a/discord/types/message.py +++ b/discord/types/message.py @@ -38,6 +38,7 @@ from .interactions import MessageInteraction, MessageInteractionMetadata from .sticker import StickerItem from .threads import Thread from .poll import Poll +from soundboard import SoundboardSound, SoundboardDefaultSound class PartialMessage(TypedDict): @@ -227,6 +228,7 @@ class Message(PartialMessage): thread: NotRequired[Thread] call: NotRequired[CallMessage] purchase_notification: NotRequired[PurchaseNotificationResponse] + soundboard_sounds: NotRequired[List[Union[SoundboardSound, SoundboardDefaultSound]]] AllowedMentionType = Literal['roles', 'users', 'everyone']