Skip to content

Commit 71a9d94

Browse files
NeloBlivionIcebluewolfPaillat-dev
authored
Apply suggestions from code review
docs review thanku Co-authored-by: Ice Wolfy <44532864+Icebluewolf@users.noreply.github.com> Co-authored-by: Paillat <jeremiecotti@ik.me> Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com>
1 parent bcf7aa1 commit 71a9d94

6 files changed

Lines changed: 30 additions & 22 deletions

File tree

discord/components.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class Component:
106106
type: :class:`ComponentType`
107107
The type of component.
108108
id: :class:`int`
109-
The component's ID. If not provided by the user, it is automatically incremented.
109+
The component's ID. If not provided by the user, it is set sequentially by Discord.
110+
The ID `0` is treated as if no ID was provided.
110111
"""
111112

112113
__slots__: tuple[str, ...] = ("type", "id")
@@ -170,7 +171,7 @@ def __init__(self, data: ComponentPayload):
170171

171172
@property
172173
def width(self):
173-
"""Return the total item width that this action row uses."""
174+
"""Return the sum of the children's widths."""
174175
t = 0
175176
for item in self.children:
176177
t += 1 if item.type is ComponentType.button else 5
@@ -572,7 +573,7 @@ def to_dict(self) -> SelectOptionPayload:
572573
class Section(Component):
573574
"""Represents a Section from Components V2.
574575
575-
This is a component that groups other components together.
576+
This is a component that groups other components together with an additional component to the right as the accessory.
576577
577578
This inherits from :class:`Component`.
578579
@@ -688,7 +689,7 @@ def from_dict(cls, data: UnfurledMediaItemPayload, state=None) -> UnfurledMediaI
688689
r._state = state
689690
return r
690691

691-
def to_dict(self):
692+
def to_dict(self) -> dict[str, str]:
692693
return {"url": self.url}
693694

694695

@@ -708,7 +709,7 @@ class Thumbnail(Component):
708709
description: Optional[:class:`str`]
709710
The thumbnail's description, up to 1024 characters.
710711
spoiler: Optional[:class:`bool`]
711-
Whether the thumbnail is a spoiler.
712+
Whether the thumbnail has the spoiler overlay.
712713
"""
713714

714715
__slots__: tuple[str, ...] = (
@@ -853,7 +854,7 @@ class FileComponent(Component):
853854
size: :class:`int`
854855
The file's size in bytes.
855856
spoiler: Optional[:class:`bool`]
856-
Whether the file is a spoiler.
857+
Whether the file has the spoiler overlay.
857858
"""
858859

859860
__slots__: tuple[str, ...] = (
@@ -886,7 +887,7 @@ def to_dict(self) -> FileComponentPayload:
886887
class Separator(Component):
887888
"""Represents a Separator from Components V2.
888889
889-
This is a component that separates other components.
890+
This is a component that visually separates components.
890891
891892
This inherits from :class:`Component`.
892893
@@ -895,7 +896,7 @@ class Separator(Component):
895896
Attributes
896897
----------
897898
divider: :class:`bool`
898-
Whether the separator is a divider (provide example?)
899+
Whether the separator will show a horizontal line in addition to vertical spacing.
899900
spacing: Optional[:class:`SeparatorSpacingSize`]
900901
The separator's spacing size.
901902
"""
@@ -937,8 +938,12 @@ class Container(Component):
937938
938939
Attributes
939940
----------
940-
items: List[:class:`MediaGalleryItem`]
941-
The media this gallery contains.
941+
components: List[:class:`Component`]
942+
The components contained in this container.
943+
accent_color: Optional[:class:`Colour`]
944+
The accent color of the container.
945+
spoiler: Optional[:class:`bool`]
946+
Whether the entire container has the spoiler overlay.
942947
"""
943948

944949
__slots__: tuple[str, ...] = (

discord/ui/container.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class Container(Item[V]):
5252
colour: Union[:class:`Colour`, :class:`int`]
5353
The accent colour of the container. Aliased to ``color`` as well.
5454
spoiler: Optional[:class:`bool`]
55-
Whether this container is a spoiler.
55+
Whether this container has the spoiler overlay.
5656
id: Optional[:class:`int`]
5757
The container's ID.
5858
"""
@@ -173,7 +173,7 @@ def remove_item(self, item: Item | str | int) -> Self:
173173
return self
174174

175175
def get_item(self, id: str | int) -> Item | None:
176-
"""Get a top-level item from this container. Roughly equivalent to `utils.get(container.items, ...)`.
176+
"""Get an item from this container. Roughly equivalent to `utils.get(container.items, ...)`.
177177
If an ``int`` is provided, the item will be retrieved by ``id``, otherwise by ``custom_id``.
178178
This method will also search for nested items.
179179
@@ -232,6 +232,8 @@ def add_text(self, content: str, id: int | None = None) -> Self:
232232
----------
233233
content: :class:`str`
234234
The content of the TextDisplay
235+
id: Optiona[:class:`int`]
236+
The text displays' ID.
235237
"""
236238

237239
text = TextDisplay(content, id=id)
@@ -267,7 +269,7 @@ def add_file(self, url: str, spoiler: bool = False, id: int | None = None) -> Se
267269
url: :class:`str`
268270
The URL of this file's media. This must be an ``attachment://`` URL that references a :class:`~discord.File`.
269271
spoiler: Optional[:class:`bool`]
270-
Whether the file is a spoiler. Defaults to ``False``.
272+
Whether the file has the spoiler overlay. Defaults to ``False``.
271273
id: Optiona[:class:`int`]
272274
The file's ID.
273275
"""
@@ -307,7 +309,7 @@ def copy_text(self) -> str:
307309

308310
@property
309311
def spoiler(self) -> bool:
310-
"""Whether the container is a spoiler. Defaults to ``False``."""
312+
"""Whether the container has the spoiler overlay. Defaults to ``False``."""
311313
return self._underlying.spoiler
312314

313315
@spoiler.setter

discord/ui/file.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class File(Item[V]):
3131
url: :class:`str`
3232
The URL of this file. This must be an ``attachment://`` URL referring to a local file used with :class:`~discord.File`.
3333
spoiler: Optional[:class:`bool`]
34-
Whether this file is a spoiler.
34+
Whether this file has the spoiler overlay.
3535
id: Optional[:class:`int`]
3636
The file component's ID.
3737
"""
@@ -73,7 +73,7 @@ def url(self, value: str) -> None:
7373

7474
@property
7575
def spoiler(self) -> bool:
76-
"""Whether the file is a spoiler. Defaults to ``False``."""
76+
"""Whether the file has the spoiler overlay. Defaults to ``False``."""
7777
return self._underlying.spoiler
7878

7979
@spoiler.setter

discord/ui/media_gallery.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ def add_item(
9090
description: Optional[:class:`str`]
9191
The media item's description, up to 1024 characters.
9292
spoiler: Optional[:class:`bool`]
93-
Whether the media item is a spoiler.
93+
Whether the media item has the spoiler overlay.
9494
9595
Raises
9696
------
@@ -99,7 +99,7 @@ def add_item(
9999
"""
100100

101101
if len(self.items) >= 10:
102-
raise ValueError("maximum number of children exceeded")
102+
raise ValueError("maximum number of items exceeded")
103103

104104
item = MediaGalleryItem(url, description=description, spoiler=spoiler)
105105

discord/ui/section.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ def set_thumbnail(
225225
description: Optional[:class:`str`]
226226
The thumbnail's description, up to 1024 characters.
227227
spoiler: Optional[:class:`bool`]
228-
Whether the thumbnail is a spoiler. Defaults to ``False``.
228+
Whether the thumbnail has the spoiler overlay. Defaults to ``False``.
229229
id: Optional[:class:`int`]
230230
The thumbnail's ID.
231231
"""
@@ -289,7 +289,7 @@ def disable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
289289

290290
def enable_all_items(self, *, exclusions: list[Item] | None = None) -> Self:
291291
"""
292-
Enables all buttons and select menus in the container.
292+
Enables all buttons and select menus in the section.
293293
At the moment, this only enables :attr:`accessory` if it is a button.
294294
295295
Parameters

discord/ui/thumbnail.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Thumbnail(Item[V]):
3030
description: Optional[:class:`str`]
3131
The thumbnail's description, up to 1024 characters.
3232
spoiler: Optional[:class:`bool`]
33-
Whether the thumbnail is a spoiler. Defaults to ``False``.
33+
Whether the thumbnail has the spoiler overlay. Defaults to ``False``.
3434
id: Optional[:class:`int`]
3535
The thumbnail's ID.
3636
"""
@@ -90,7 +90,8 @@ def description(self, description: str | None) -> None:
9090

9191
@property
9292
def spoiler(self) -> bool:
93-
"""Whether the thumbnail is a spoiler. Defaults to ``False``."""
93+
"""Whether the thumbnail has the spoiler overlay. Defaults to ``False``."""
94+
9495
return self._underlying.spoiler
9596

9697
@spoiler.setter

0 commit comments

Comments
 (0)