Browse Source

Merge 03453a8cad into 26855160f8

pull/10102/merge
Soheab 1 month ago
committed by GitHub
parent
commit
e5bef01151
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 25
      discord/message.py
  2. 2
      discord/types/message.py

25
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
@ -2131,6 +2133,10 @@ class Message(PartialMessage, Hashable):
message_snapshots: List[:class:`MessageSnapshot`] message_snapshots: List[:class:`MessageSnapshot`]
The message snapshots attached to this message. 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 .. versionadded:: 2.5
""" """
@ -2171,6 +2177,7 @@ class Message(PartialMessage, Hashable):
'call', 'call',
'purchase_notification', 'purchase_notification',
'message_snapshots', 'message_snapshots',
'soundboard_sounds',
) )
if TYPE_CHECKING: if TYPE_CHECKING:
@ -2210,6 +2217,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:
@ -2313,7 +2321,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]) # type: ignore getattr(self, f'_handle_{handler}')(data[handler]) # type: ignore
except KeyError: except KeyError:
@ -2506,6 +2514,21 @@ 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_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( 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