Skip to content

Commit 33b2cc1

Browse files
committed
docs: add/adjust docstrings for components
1 parent 0d11f77 commit 33b2cc1

File tree

1 file changed

+130
-16
lines changed

1 file changed

+130
-16
lines changed

interactions/models/discord/components.py

Lines changed: 130 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,18 @@
5454

5555

5656
class UnfurledMediaItem(DictSerializationMixin):
57-
"""A basic object for making media items."""
57+
"""
58+
A basic object for making media items.
59+
60+
Attributes:
61+
url str: The source url of the media.
62+
proxy_url Optional[str]: A proxied url of the media. Only present when provided by Discord.
63+
height Optional[int]: The height of the media. Only present when provided by Discord.
64+
width Optional[int]: The width of the media. Only present when provided by Discord.
65+
content_type Optional[str]: The content type of the media. Only present when provided by Discord.
66+
loading_state Optional[UnfurledMediaItemLoadingState]: The loading state of the media.
67+
68+
"""
5869

5970
url: str
6071
proxy_url: Optional[str] = None
@@ -569,12 +580,12 @@ class StringSelectMenu(BaseSelectMenu):
569580
570581
Attributes:
571582
options List[dict]: The choices in the select, max 25.
572-
custom_id str: A developer-defined identifier for the button, max 100 characters.
583+
custom_id str: A developer-defined identifier for the select, max 100 characters.
573584
placeholder str: The custom placeholder text to show if nothing is selected, max 100 characters.
574585
min_values Optional[int]: The minimum number of items that must be chosen. (default 1, min 0, max 25)
575586
max_values Optional[int]: The maximum number of items that can be chosen. (default 1, max 25)
576587
disabled bool: Disable the select and make it not intractable, default false.
577-
type Union[ComponentType, int]: The action role type number defined by discord. This cannot be modified.
588+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
578589
579590
"""
580591

@@ -630,12 +641,13 @@ class UserSelectMenu(DefaultableSelectMenu):
630641
Represents a user select component.
631642
632643
Attributes:
633-
custom_id str: A developer-defined identifier for the button, max 100 characters.
634644
placeholder str: The custom placeholder text to show if nothing is selected, max 100 characters.
635645
min_values Optional[int]: The minimum number of items that must be chosen. (default 1, min 0, max 25)
636646
max_values Optional[int]: The maximum number of items that can be chosen. (default 1, max 25)
647+
custom_id str: A developer-defined identifier for the select, max 100 characters.
648+
default_values list[BaseUser, Member, SelectDefaultValues]: A list of default values to pre-select in the select.
637649
disabled bool: Disable the select and make it not intractable, default false.
638-
type Union[ComponentType, int]: The action role type number defined by discord. This cannot be modified.
650+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
639651
640652
"""
641653

@@ -650,8 +662,6 @@ def __init__(
650662
list[
651663
Union[
652664
"interactions.models.discord.BaseUser",
653-
"interactions.models.discord.Role",
654-
"interactions.models.discord.BaseChannel",
655665
"interactions.models.discord.Member",
656666
SelectDefaultValues,
657667
],
@@ -674,15 +684,16 @@ def __init__(
674684

675685
class RoleSelectMenu(DefaultableSelectMenu):
676686
"""
677-
Represents a user select component.
687+
Represents a role select component.
678688
679689
Attributes:
680-
custom_id str: A developer-defined identifier for the button, max 100 characters.
681690
placeholder str: The custom placeholder text to show if nothing is selected, max 100 characters.
682691
min_values Optional[int]: The minimum number of items that must be chosen. (default 1, min 0, max 25)
683692
max_values Optional[int]: The maximum number of items that can be chosen. (default 1, max 25)
693+
custom_id str: A developer-defined identifier for the select, max 100 characters.
694+
default_values list[Role, SelectDefaultValues]: A list of default values to pre-select in the select.
684695
disabled bool: Disable the select and make it not intractable, default false.
685-
type Union[ComponentType, int]: The action role type number defined by discord. This cannot be modified.
696+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
686697
687698
"""
688699

@@ -697,10 +708,7 @@ def __init__(
697708
default_values: (
698709
list[
699710
Union[
700-
"interactions.models.discord.BaseUser",
701711
"interactions.models.discord.Role",
702-
"interactions.models.discord.BaseChannel",
703-
"interactions.models.discord.Member",
704712
SelectDefaultValues,
705713
],
706714
]
@@ -720,6 +728,20 @@ def __init__(
720728

721729

722730
class MentionableSelectMenu(DefaultableSelectMenu):
731+
"""
732+
Represents a mentional select component, which includes users, roles, and channels.
733+
734+
Attributes:
735+
placeholder str: The custom placeholder text to show if nothing is selected, max 100 characters.
736+
min_values Optional[int]: The minimum number of items that must be chosen. (default 1, min 0, max 25)
737+
max_values Optional[int]: The maximum number of items that can be chosen. (default 1, max 25)
738+
custom_id str: A developer-defined identifier for the select, max 100 characters.
739+
default_values list[BaseUser, Role, BaseChannel, Member, SelectDefaultValues]: A list of default values to pre-select in the select.
740+
disabled bool: Disable the select and make it not intractable, default false.
741+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
742+
743+
"""
744+
723745
def __init__(
724746
self,
725747
*,
@@ -754,6 +776,20 @@ def __init__(
754776

755777

756778
class ChannelSelectMenu(DefaultableSelectMenu):
779+
"""
780+
Represents a chanel select component.
781+
782+
Attributes:
783+
placeholder str: The custom placeholder text to show if nothing is selected, max 100 characters.
784+
min_values Optional[int]: The minimum number of items that must be chosen. (default 1, min 0, max 25)
785+
max_values Optional[int]: The maximum number of items that can be chosen. (default 1, max 25)
786+
custom_id str: A developer-defined identifier for the select, max 100 characters.
787+
default_values list[BaseChannel, SelectDefaultValues]: A list of default values to pre-select in the select.
788+
disabled bool: Disable the select and make it not intractable, default false.
789+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
790+
791+
"""
792+
757793
def __init__(
758794
self,
759795
*,
@@ -766,10 +802,7 @@ def __init__(
766802
default_values: (
767803
list[
768804
Union[
769-
"interactions.models.discord.BaseUser",
770-
"interactions.models.discord.Role",
771805
"interactions.models.discord.BaseChannel",
772-
"interactions.models.discord.Member",
773806
SelectDefaultValues,
774807
],
775808
]
@@ -812,6 +845,16 @@ def to_dict(self) -> discord_typings.SelectMenuComponentData:
812845

813846

814847
class SectionComponent(BaseComponent):
848+
"""
849+
A top-level layout component that allows you to join text contextually with an accessory.
850+
851+
Attributes:
852+
components list[TextDisplayComponent]: The text components to include in this section.
853+
accessory Button | ThumbnailComponent: The accessory to include in this section.
854+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
855+
856+
"""
857+
815858
components: "list[TextDisplayComponent]"
816859
accessory: "Button | ThumbnailComponent"
817860

@@ -840,6 +883,15 @@ def to_dict(self) -> dict:
840883

841884

842885
class TextDisplayComponent(BaseComponent):
886+
"""
887+
A top-level content component that allows you to add text to your message.
888+
889+
Attributes:
890+
content str: Text that will be displayed, similar to a message.
891+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
892+
893+
"""
894+
843895
content: str
844896

845897
def __init__(self, content: str):
@@ -861,6 +913,17 @@ def to_dict(self) -> dict:
861913

862914

863915
class ThumbnailComponent(BaseComponent):
916+
"""
917+
A content component that is a small image only usable as an accessory in a section.
918+
919+
Attributes:
920+
media UnfurledMediaItem: The media item to display as a thumbnail.
921+
description Optional[str]: An optional description to show below the thumbnail.
922+
spoiler bool: Whether the thumbnail should be marked as a spoiler, default false.
923+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
924+
925+
"""
926+
864927
media: UnfurledMediaItem
865928
description: Optional[str] = None
866929
spoiler: bool = False
@@ -892,6 +955,17 @@ def to_dict(self) -> dict:
892955

893956

894957
class MediaGalleryItem(DictSerializationMixin):
958+
"""
959+
A basic object for displaying a media attachment.
960+
961+
Attributes:
962+
media UnfurledMediaItem: The media item to display in the gallery.
963+
description Optional[str]: An optional description to show below the media.
964+
spoiler bool: Whether the media should be marked as a spoiler, default false.
965+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
966+
967+
"""
968+
895969
media: UnfurledMediaItem
896970
description: Optional[str] = None
897971
spoiler: bool = False
@@ -921,6 +995,15 @@ def to_dict(self) -> dict:
921995

922996

923997
class MediaGalleryComponent(BaseComponent):
998+
"""
999+
A top-level content component that allows you to display 1-10 media attachments in an organized gallery format.
1000+
1001+
Attributes:
1002+
items list[MediaGalleryItem]: A list of media gallery items to display, max 10.
1003+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
1004+
1005+
"""
1006+
9241007
items: list[MediaGalleryItem]
9251008

9261009
def __init__(self, items: list[MediaGalleryItem] | None = None):
@@ -942,6 +1025,16 @@ def to_dict(self) -> dict:
9421025

9431026

9441027
class FileComponent(BaseComponent):
1028+
"""
1029+
A top-level component that allows you to display an uploaded file in a component.
1030+
1031+
Attributes:
1032+
file UnfurledMediaItem: The media item to display as a file.
1033+
spoiler bool: Whether the file should be marked as a spoiler, default false.
1034+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
1035+
1036+
"""
1037+
9451038
file: UnfurledMediaItem
9461039
spoiler: bool = False
9471040

@@ -966,6 +1059,16 @@ def to_dict(self) -> dict:
9661059

9671060

9681061
class SeparatorComponent(BaseComponent):
1062+
"""
1063+
A top-level layout component that adds vertical padding and visual division between other components.
1064+
1065+
Attributes:
1066+
divider bool: Whether this is a divider, which adds a horizontal line, default false.
1067+
spacing SeparatorSpacingSize | int: The amount of vertical space to add, default SeparatorSpacingSize.SMALL.
1068+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
1069+
1070+
"""
1071+
9691072
divider: bool = False
9701073
spacing: SeparatorSpacingSize = SeparatorSpacingSize.SMALL
9711074

@@ -990,6 +1093,17 @@ def to_dict(self) -> dict:
9901093

9911094

9921095
class ContainerComponent(BaseComponent):
1096+
"""
1097+
A top-level layout component. Containers are visually distinct from surrounding components and have an optional customizable color bar.
1098+
1099+
Attributes:
1100+
components list[ActionRow | SectionComponent | TextDisplayComponent | MediaGalleryComponent | FileComponent | SeparatorComponent]: The components to include in this container.
1101+
accent_color Optional[int]: The color of the container, as a hex value, default None.
1102+
spoiler bool: Whether the container should be marked as a spoiler, default false.
1103+
type Union[ComponentType, int]: The type of component, as defined by discord. This cannot be modified.
1104+
1105+
"""
1106+
9931107
components: list[
9941108
ActionRow | SectionComponent | TextDisplayComponent | MediaGalleryComponent | FileComponent | SeparatorComponent
9951109
]

0 commit comments

Comments
 (0)