Skip to content

Commit 4a1268d

Browse files
committed
docs for select aliases
1 parent 161b0d8 commit 4a1268d

File tree

2 files changed

+70
-13
lines changed

2 files changed

+70
-13
lines changed

discord/ui/select.py

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ class Select(Generic[V, ST], Item[V]):
106106
:attr:`discord.ComponentType.string_select`, :attr:`discord.ComponentType.user_select`,
107107
:attr:`discord.ComponentType.role_select`, :attr:`discord.ComponentType.mentionable_select`,
108108
or :attr:`discord.ComponentType.channel_select`.
109+
110+
The default is :attr:`discord.ComponentType.string`, but if this is created using any of the provided
111+
aliases: :class:`StringSelect`, :class:`RoleSelect`, :class:`UserSelect`, :class:`MentionableSelect`, or
112+
:class:`ChannelSelect`, the default will be its respective select type.
109113
custom_id: :class:`str`
110114
The ID of the select menu that gets received during an interaction.
111115
If not given then one is generated for you.
@@ -217,7 +221,7 @@ def __init__(
217221
@overload
218222
def __init__(
219223
self,
220-
select_type: Literal[ComponentType.channel_select],
224+
select_type: Literal[ComponentType.channel_select] = ...,
221225
*,
222226
custom_id: str | None = ...,
223227
placeholder: str | None = ...,
@@ -240,7 +244,7 @@ def __init__(
240244
ComponentType.user_select,
241245
ComponentType.role_select,
242246
ComponentType.mentionable_select,
243-
],
247+
] = ...,
244248
*,
245249
custom_id: str | None = ...,
246250
placeholder: str | None = ...,
@@ -766,7 +770,7 @@ def from_component(cls: type[S], component: SelectMenu) -> S:
766770
id=component.id,
767771
required=component.required,
768772
default_values=component.default_values,
769-
)
773+
) # type: ignore
770774

771775
@property
772776
def type(self) -> ComponentType:
@@ -784,29 +788,71 @@ def uses_label(self) -> bool:
784788

785789
if TYPE_CHECKING:
786790
StringSelect = Select[V, str]
787-
"""A typed alias for :class:`Select` for string values."""
791+
"""A typed alias for :class:`Select` for string values.
792+
793+
When creating an instance with this, it will automatically provide the ``select_type``
794+
parameter as a :attr:`discord.ComponentType.string_select`.
795+
"""
788796
UserSelect = Select[V, User | Member]
789-
"""A typed alias for :class:`Select` for user-like values."""
797+
"""A typed alias for :class:`Select` for user-like values.
798+
799+
When creating an instance with this, it will automatically provide the ``select_type``
800+
parameter as a :attr:`discord.ComponentType.user_select`.
801+
"""
790802
RoleSelect = Select[V, Role]
791-
"""A typed alias for :class:`Select` for role values."""
803+
"""A typed alias for :class:`Select` for role values.
804+
805+
When creating an instance with this, it will automatically provide the ``select_type``
806+
parameter as a :attr:`discord.ComponentType.role_select`.
807+
"""
792808
MentionableSelect = Select[V, User | Member | Role]
793-
"""A typed alias for :class:`Select` for mentionable (role and user-like) values."""
809+
"""A typed alias for :class:`Select` for mentionable (role and user-like) values.
810+
811+
When creating an instance with this, it will automatically provide the ``select_type``
812+
parameter as a :attr:`discord.ComponentType.mentionable_select`.
813+
"""
794814
ChannelSelect = Select[V, GuildChannel | Thread]
795-
"""A typed alias for :class:`Select` for channel values."""
815+
"""A typed alias for :class:`Select` for channel values.
816+
817+
When creating an instance with this, it will automatically provide the ``select_type``
818+
parameter as a :attr:`discord.ComponentType.channel_select`.
819+
"""
796820
else:
797-
StringSelect: Select[V, str] = partial(
821+
class select_partial(partial):
822+
@property
823+
def __class__(self) -> type[Select]:
824+
return Select
825+
826+
StringSelect: Select[V, str] = select_partial(
798827
Select, select_type=ComponentType.string_select
799828
)
800-
UserSelect: Select[V, User | Member] = partial(
829+
"""An alias for :class:`Select` that will pass :attr:`discord.ComponentType.string_select`
830+
as its default ``select_type``.
831+
"""
832+
UserSelect: Select[V, User | Member] = select_partial(
801833
Select, select_type=ComponentType.user_select
802834
)
803-
RoleSelect: Select[V, Role] = partial(Select, select_type=ComponentType.role_select)
804-
MentionableSelect: Select[V, Role | User | Member] = partial(
835+
"""An alias for :class:`Select` that will pass :attr:`discord.ComponentType.user_select`
836+
as its default ``select_type``.
837+
"""
838+
RoleSelect: Select[V, Role] = select_partial(Select, select_type=ComponentType.role_select)
839+
"""An alias for :class:`Select` that will pass :attr:`discord.ComponentType.role_select`
840+
as its default ``select_type``.
841+
"""
842+
MentionableSelect: Select[V, Role | User | Member] = select_partial(
805843
Select, select_type=ComponentType.mentionable_select
806844
)
807-
ChannelSelect: Select[V, GuildChannel | Thread] = partial(
845+
"""An alias for :class:`Select` that will pass :attr:`discord.ComponentType.mentionable_select`
846+
as its default ``select_type``.
847+
"""
848+
ChannelSelect: Select[V, GuildChannel | Thread] = select_partial(
808849
Select, select_type=ComponentType.channel_select
809850
)
851+
"""An alias for :class:`Select` that will pass :attr:`discord.ComponentType.channel_select`
852+
as its default ``select_type``.
853+
"""
854+
855+
select_partial.__bases__ = (Select, partial) # lie to checkers
810856

811857

812858
_select_types = (

docs/api/ui_kit.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ Objects
5555
:members:
5656
:inherited-members:
5757

58+
59+
.. autoclass:: discord.ui.StringSelect
60+
61+
.. autoclass:: discord.ui.UserSelect
62+
63+
.. autoclass:: discord.ui.RoleSelect
64+
65+
.. autoclass:: discord.ui.MentionableSelect
66+
67+
.. autoclass:: discord.ui.ChannelSelect
68+
5869
.. attributetable:: discord.ui.Section
5970

6071
.. autoclass:: discord.ui.Section

0 commit comments

Comments
 (0)