Browse Source

add attachment_id and name & size

pull/10166/head
DA-344 1 month ago
parent
commit
d9f0be78cc
  1. 16
      discord/components.py
  2. 3
      discord/types/components.py

16
discord/components.py

@ -47,7 +47,7 @@ from .enums import (
)
from .flags import AttachmentFlags
from .colour import Colour
from .utils import get_slots, MISSING
from .utils import get_slots, MISSING, _get_as_snowflake
from .partial_emoji import PartialEmoji, _EmojiTag
if TYPE_CHECKING:
@ -926,6 +926,9 @@ class UnfurledMediaItem(AssetMixin):
The media item's placeholder.
loading_state: Optional[:class:`MediaItemLoadingState`]
The loading state of this media item.
attachment_id: Optional[:class:`int`]
The attachment id this media item points to, only available if the url points to a local file
uploaded within the component message.
"""
__slots__ = (
@ -937,6 +940,7 @@ class UnfurledMediaItem(AssetMixin):
'_flags',
'placeholder',
'loading_state',
'attachment_id',
'_state',
)
@ -950,6 +954,7 @@ class UnfurledMediaItem(AssetMixin):
self._flags: int = 0
self.placeholder: Optional[str] = None
self.loading_state: Optional[MediaItemLoadingState] = None
self.attachment_id: Optional[int] = None
self._state: Optional[ConnectionState] = None
@property
@ -974,6 +979,7 @@ class UnfurledMediaItem(AssetMixin):
loading_state = data.get('loading_state')
if loading_state is not None:
self.loading_state = try_enum(MediaItemLoadingState, loading_state)
self.attachment_id = _get_as_snowflake(data, 'attachment_id')
self._state = state
def __repr__(self) -> str:
@ -1118,12 +1124,18 @@ class FileComponent(Component):
Whether this file is flagged as a spoiler.
id: Optional[:class:`int`]
The ID of this component.
name: Optional[:class:`str`]
The displayed file name, only available when received from the API.
size: Optional[:class:`int`]
The file size in MiB, only available when received from the API.
"""
__slots__ = (
'media',
'spoiler',
'id',
'name',
'size',
)
__repr_info__ = __slots__
@ -1132,6 +1144,8 @@ class FileComponent(Component):
self.media: UnfurledMediaItem = UnfurledMediaItem._from_data(data['file'], state)
self.spoiler: bool = data.get('spoiler', False)
self.id: Optional[int] = data.get('id')
self.name: Optional[str] = data.get('name')
self.size: Optional[int] = data.get('size')
@property
def type(self) -> Literal[ComponentType.file]:

3
discord/types/components.py

@ -144,6 +144,7 @@ class UnfurledMediaItem(TypedDict):
content_type: NotRequired[str]
placeholder: str
loading_state: MediaItemLoadingState
attachment_id: NotRequired[int]
flags: NotRequired[int]
@ -169,6 +170,8 @@ class FileComponent(ComponentBase):
type: Literal[13]
file: UnfurledMediaItem
spoiler: NotRequired[bool]
name: NotRequired[str]
size: NotRequired[int]
class SeparatorComponent(ComponentBase):

Loading…
Cancel
Save