diff --git a/discord/message.py b/discord/message.py index 547e9c433..a5431f80c 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 @@ -2131,6 +2133,10 @@ class Message(PartialMessage, Hashable): message_snapshots: List[:class:`MessageSnapshot`] The message snapshots attached to this message. + .. versionadded:: 2.5 + soundboard_sounds: List[Union[:class:`SoundboardSound`, :class:`SoundboardDefaultSound`]] + The soundboard sounds mentioned in this message. + .. versionadded:: 2.5 """ @@ -2171,6 +2177,7 @@ class Message(PartialMessage, Hashable): 'call', 'purchase_notification', 'message_snapshots', + 'soundboard_sounds', ) if TYPE_CHECKING: @@ -2210,6 +2217,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: @@ -2313,7 +2321,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]) # type: ignore except KeyError: @@ -2506,6 +2514,21 @@ class Message(PartialMessage, Hashable): else: self.call = None + def _handle_soundboard_sounds(self, data: List[SoundboardSoundPayload]): + for sound in data: + guild_id = utils._get_as_snowflake(sound, 'guild_id') + try: + if guild_id: + self.soundboard_sounds.append( + SoundboardSound( + state=self._state, data=sound, guild=self._state._get_or_create_unavailable_guild(guild_id) + ) + ) + else: + self.soundboard_sounds.append(SoundboardDefaultSound(state=self._state, data=sound)) # type: ignore # EAFP + 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']