Browse Source

Add the placeholder fields to the attachment object

Implements #10458
pull/10459/head
___ 3 weeks ago
parent
commit
fd20f5d9e5
  1. 15
      discord/message.py
  2. 2
      discord/types/message.py

15
discord/message.py

@ -206,6 +206,17 @@ class Attachment(Hashable):
The normalised version of the attachment's filename. The normalised version of the attachment's filename.
.. versionadded:: 2.5 .. versionadded:: 2.5
placeholder: Optional[:class:`str`]
A `thumbhash <https://evanw.github.io/thumbhash/>`_, of the
attachment, if it's an image or video. Otherwise, ``None``.
.. versionadded:: 2.8
placeholder_version: Optional[:class:`int`]
The version of the placeholder, if the attachment is an image
or video. Otherwise, ``None``.
.. versionadded:: 2.8
""" """
__slots__ = ( __slots__ = (
@ -224,6 +235,8 @@ class Attachment(Hashable):
'waveform', 'waveform',
'_flags', '_flags',
'title', 'title',
'placeholder',
'placeholder_version',
) )
def __init__(self, *, data: AttachmentPayload, state: ConnectionState): def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
@ -240,6 +253,8 @@ class Attachment(Hashable):
self.ephemeral: bool = data.get('ephemeral', False) self.ephemeral: bool = data.get('ephemeral', False)
self.duration: Optional[float] = data.get('duration_secs') self.duration: Optional[float] = data.get('duration_secs')
self.title: Optional[str] = data.get('title') self.title: Optional[str] = data.get('title')
self.placeholder: Optional[str] = data.get('placeholder')
self.placeholder_version: Optional[int] = data.get('placeholder_version')
waveform = data.get('waveform') waveform = data.get('waveform')
self.waveform: Optional[bytes] = utils._base64_to_bytes(waveform) if waveform is not None else None self.waveform: Optional[bytes] = utils._base64_to_bytes(waveform) if waveform is not None else None

2
discord/types/message.py

@ -84,6 +84,8 @@ class Attachment(TypedDict):
duration_secs: NotRequired[float] duration_secs: NotRequired[float]
waveform: NotRequired[str] waveform: NotRequired[str]
flags: NotRequired[int] flags: NotRequired[int]
placeholder: NotRequired[Optional[str]]
placeholder_version: NotRequired[Optional[int]]
MessageActivityType = Literal[1, 2, 3, 5] MessageActivityType = Literal[1, 2, 3, 5]

Loading…
Cancel
Save