Browse Source

chore: Add notes and versionaddeds

pull/10166/head
DA-344 3 months ago
parent
commit
faa31ffc52
  1. 67
      discord/components.py

67
discord/components.py

@ -719,7 +719,7 @@ class SectionComponent(Component):
---------- ----------
components: List[Union[:class:`TextDisplay`, :class:`Button`]] components: List[Union[:class:`TextDisplay`, :class:`Button`]]
The components on this section. The components on this section.
accessory: Optional[:class:`Component`] accessory: :class:`Component`
The section accessory. The section accessory.
""" """
@ -762,6 +762,8 @@ class ThumbnailComponent(Component):
The user constructible and usable type to create a thumbnail is :class:`discord.ui.Thumbnail` The user constructible and usable type to create a thumbnail is :class:`discord.ui.Thumbnail`
not this one. not this one.
.. versionadded:: 2.6
Attributes Attributes
---------- ----------
media: :class:`UnfurledMediaItem` media: :class:`UnfurledMediaItem`
@ -772,7 +774,13 @@ class ThumbnailComponent(Component):
Whether this thumbnail is flagged as a spoiler. Whether this thumbnail is flagged as a spoiler.
""" """
__slots__ = () __slots__ = (
'media',
'spoiler',
'description',
)
__repr_info__ = __slots__
def __init__( def __init__(
self, self,
@ -801,6 +809,11 @@ class TextDisplay(Component):
This inherits from :class:`Component`. This inherits from :class:`Component`.
.. note::
The user constructible and usable type to create a text display is
:class:`discord.ui.TextDisplay` not this one.
.. versionadded:: 2.6 .. versionadded:: 2.6
Attributes Attributes
@ -809,6 +822,10 @@ class TextDisplay(Component):
The content that this display shows. The content that this display shows.
""" """
__slots__ = ('content',)
__repr_info__ = __slots__
def __init__(self, data: TextComponentPayload) -> None: def __init__(self, data: TextComponentPayload) -> None:
self.content: str = data['content'] self.content: str = data['content']
@ -826,6 +843,8 @@ class TextDisplay(Component):
class UnfurledMediaItem(AssetMixin): class UnfurledMediaItem(AssetMixin):
"""Represents an unfurled media item. """Represents an unfurled media item.
.. versionadded:: 2.6
Parameters Parameters
---------- ----------
url: :class:`str` url: :class:`str`
@ -896,6 +915,9 @@ class UnfurledMediaItem(AssetMixin):
self.loading_state = try_enum(MediaItemLoadingState, data['loading_state']) self.loading_state = try_enum(MediaItemLoadingState, data['loading_state'])
self._state = state self._state = state
def __repr__(self) -> str:
return f'<UnfurledMediaItem url={self.url}>'
def to_dict(self): def to_dict(self):
return { return {
'url': self.url, 'url': self.url,
@ -905,6 +927,8 @@ class UnfurledMediaItem(AssetMixin):
class MediaGalleryItem: class MediaGalleryItem:
"""Represents a :class:`MediaGalleryComponent` media item. """Represents a :class:`MediaGalleryComponent` media item.
.. versionadded:: 2.6
Parameters Parameters
---------- ----------
media: Union[:class:`str`, :class:`UnfurledMediaItem`] media: Union[:class:`str`, :class:`UnfurledMediaItem`]
@ -936,6 +960,9 @@ class MediaGalleryItem:
self.spoiler: bool = spoiler self.spoiler: bool = spoiler
self._state: Optional[ConnectionState] = None self._state: Optional[ConnectionState] = None
def __repr__(self) -> str:
return f'<MediaGalleryItem media={self.media!r}>'
@classmethod @classmethod
def _from_data(cls, data: MediaGalleryItemPayload, state: Optional[ConnectionState]) -> MediaGalleryItem: def _from_data(cls, data: MediaGalleryItemPayload, state: Optional[ConnectionState]) -> MediaGalleryItem:
media = data['media'] media = data['media']
@ -968,13 +995,22 @@ class MediaGalleryComponent(Component):
This inherits from :class:`Component`. This inherits from :class:`Component`.
.. note::
The user constructible and usable type for creating a media gallery is
:class:`discord.ui.MediaGallery` not this one.
.. versionadded:: 2.6
Attributes Attributes
---------- ----------
items: List[:class:`MediaGalleryItem`] items: List[:class:`MediaGalleryItem`]
The items this gallery has. The items this gallery has.
""" """
__slots__ = ('items', 'id') __slots__ = ('items',)
__repr_info__ = __slots__
def __init__(self, data: MediaGalleryComponentPayload, state: Optional[ConnectionState]) -> None: def __init__(self, data: MediaGalleryComponentPayload, state: Optional[ConnectionState]) -> None:
self.items: List[MediaGalleryItem] = MediaGalleryItem._from_gallery(data['items'], state) self.items: List[MediaGalleryItem] = MediaGalleryItem._from_gallery(data['items'], state)
@ -995,6 +1031,13 @@ class FileComponent(Component):
This inherits from :class:`Component`. This inherits from :class:`Component`.
.. note::
The user constructible and usable type for create a file component is
:class:`discord.ui.File` not this one.
.. versionadded:: 2.6
Attributes Attributes
---------- ----------
media: :class:`UnfurledMediaItem` media: :class:`UnfurledMediaItem`
@ -1008,6 +1051,8 @@ class FileComponent(Component):
'spoiler', 'spoiler',
) )
__repr_info__ = __slots__
def __init__(self, data: FileComponentPayload, state: Optional[ConnectionState]) -> None: def __init__(self, data: FileComponentPayload, state: Optional[ConnectionState]) -> None:
self.media: UnfurledMediaItem = UnfurledMediaItem._from_data(data['file'], state) self.media: UnfurledMediaItem = UnfurledMediaItem._from_data(data['file'], state)
self.spoiler: bool = data.get('spoiler', False) self.spoiler: bool = data.get('spoiler', False)
@ -1029,6 +1074,13 @@ class SeparatorComponent(Component):
This inherits from :class:`Component`. This inherits from :class:`Component`.
.. note::
The user constructible and usable type for creating a separator is
:class:`discord.ui.Separator` not this one.
.. versionadded:: 2.6
Attributes Attributes
---------- ----------
spacing: :class:`SeparatorSize` spacing: :class:`SeparatorSize`
@ -1042,6 +1094,8 @@ class SeparatorComponent(Component):
'visible', 'visible',
) )
__repr_info__ = __slots__
def __init__( def __init__(
self, self,
data: SeparatorComponentPayload, data: SeparatorComponentPayload,
@ -1066,6 +1120,13 @@ class Container(Component):
This inherits from :class:`Component`. This inherits from :class:`Component`.
.. note::
The user constructible and usable type for creating a container is
:class:`discord.ui.Container` not this one.
.. versionadded:: 2.6
Attributes Attributes
---------- ----------
children: :class:`Component` children: :class:`Component`

Loading…
Cancel
Save