Browse Source

Add support for soundboard_sounds field on message

pull/10102/head
Soheab_ 4 months ago
parent
commit
a20e3cdee2
  1. 17
      discord/message.py
  2. 2
      discord/types/message.py

17
discord/message.py

@ -65,6 +65,7 @@ from .sticker import StickerItem, GuildSticker
from .threads import Thread from .threads import Thread
from .channel import PartialMessageable from .channel import PartialMessageable
from .poll import Poll from .poll import Poll
from .soundboard import SoundboardSound, SoundboardDefaultSound
if TYPE_CHECKING: if TYPE_CHECKING:
from typing_extensions import Self from typing_extensions import Self
@ -81,6 +82,7 @@ if TYPE_CHECKING:
CallMessage as CallMessagePayload, CallMessage as CallMessagePayload,
PurchaseNotificationResponse as PurchaseNotificationResponsePayload, PurchaseNotificationResponse as PurchaseNotificationResponsePayload,
GuildProductPurchase as GuildProductPurchasePayload, GuildProductPurchase as GuildProductPurchasePayload,
SoundboardSound as SoundboardSoundPayload,
) )
from .types.interactions import MessageInteraction as MessageInteractionPayload from .types.interactions import MessageInteraction as MessageInteractionPayload
@ -2158,6 +2160,7 @@ class Message(PartialMessage, Hashable):
'call', 'call',
'purchase_notification', 'purchase_notification',
'message_snapshots', 'message_snapshots',
'soundboard_sounds',
) )
if TYPE_CHECKING: if TYPE_CHECKING:
@ -2197,6 +2200,7 @@ class Message(PartialMessage, Hashable):
self.application_id: Optional[int] = utils._get_as_snowflake(data, 'application_id') 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.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.message_snapshots: List[MessageSnapshot] = MessageSnapshot._from_value(state, data.get('message_snapshots'))
self.soundboard_sounds: List[Union[SoundboardSound, SoundboardDefaultSound]] = []
self.poll: Optional[Poll] = None self.poll: Optional[Poll] = None
try: try:
@ -2299,7 +2303,7 @@ class Message(PartialMessage, Hashable):
else: else:
self.purchase_notification = PurchaseNotification(purchase_notification) 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: try:
getattr(self, f'_handle_{handler}')(data[handler]) getattr(self, f'_handle_{handler}')(data[handler])
except KeyError: except KeyError:
@ -2492,6 +2496,17 @@ class Message(PartialMessage, Hashable):
else: else:
self.call = None 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( def _rebind_cached_references(
self, self,
new_guild: Guild, new_guild: Guild,

2
discord/types/message.py

@ -38,6 +38,7 @@ from .interactions import MessageInteraction, MessageInteractionMetadata
from .sticker import StickerItem from .sticker import StickerItem
from .threads import Thread from .threads import Thread
from .poll import Poll from .poll import Poll
from soundboard import SoundboardSound, SoundboardDefaultSound
class PartialMessage(TypedDict): class PartialMessage(TypedDict):
@ -227,6 +228,7 @@ class Message(PartialMessage):
thread: NotRequired[Thread] thread: NotRequired[Thread]
call: NotRequired[CallMessage] call: NotRequired[CallMessage]
purchase_notification: NotRequired[PurchaseNotificationResponse] purchase_notification: NotRequired[PurchaseNotificationResponse]
soundboard_sounds: NotRequired[List[Union[SoundboardSound, SoundboardDefaultSound]]]
AllowedMentionType = Literal['roles', 'users', 'everyone'] AllowedMentionType = Literal['roles', 'users', 'everyone']

Loading…
Cancel
Save