Skip to content

Commit d4dc1c5

Browse files
authored
add select overloads
1 parent 5410e00 commit d4dc1c5

File tree

3 files changed

+114
-4
lines changed

3 files changed

+114
-4
lines changed

discord/ui/action_row.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
from __future__ import annotations
22

33
from functools import partial
4+
from collections.abc import Sequence
45
from typing import TYPE_CHECKING, ClassVar, Iterator, TypeVar
56

67
from ..components import ActionRow as ActionRowComponent
7-
from ..components import SelectOption, _component_factory
8+
from ..components import SelectOption, SelectDefaultValue, _component_factory
89
from ..enums import ButtonStyle, ChannelType, ComponentType
910
from ..utils import find, get
1011
from .button import Button
@@ -210,6 +211,53 @@ def add_button(
210211

211212
return self.add_item(button)
212213

214+
@overload
215+
def add_select(
216+
self,
217+
select_type: Literal[ComponentType.string_select] = ...,
218+
*,
219+
custom_id: str | None = ...,
220+
placeholder: str | None = ...,
221+
min_values: int = ...,
222+
max_values: int = ...,
223+
options: list[SelectOption] | None = ...,
224+
disabled: bool = ...,
225+
id: int | None = ...,
226+
) -> None: ...
227+
228+
@overload
229+
def add_select(
230+
self,
231+
select_type: Literal[ComponentType.channel_select] = ...,
232+
*,
233+
custom_id: str | None = ...,
234+
placeholder: str | None = ...,
235+
min_values: int = ...,
236+
max_values: int = ...,
237+
channel_types: list[ChannelType] | None = ...,
238+
disabled: bool = ...,
239+
id: int | None = ...,
240+
default_values: Sequence[SelectDefaultValue] | None = ...,
241+
) -> None: ...
242+
243+
@overload
244+
def add_select(
245+
self,
246+
select_type: Literal[
247+
ComponentType.user_select,
248+
ComponentType.role_select,
249+
ComponentType.mentionable_select,
250+
] = ...,
251+
*,
252+
custom_id: str | None = ...,
253+
placeholder: str | None = ...,
254+
min_values: int = ...,
255+
max_values: int = ...,
256+
disabled: bool = ...,
257+
id: int | None = ...,
258+
default_values: Sequence[SelectDefaultValue] | None = ...,
259+
) -> None: ...
260+
213261
def add_select(
214262
self,
215263
select_type: ComponentType = ComponentType.string_select,
@@ -222,6 +270,7 @@ def add_select(
222270
channel_types: list[ChannelType] | None = None,
223271
disabled: bool = False,
224272
id: int | None = None,
273+
default_values: Sequence[SelectDefaultValue] | None = None,
225274
) -> Self:
226275
"""Adds a :class:`Select` to the container.
227276
@@ -256,6 +305,11 @@ def add_select(
256305
Whether the select is disabled or not. Defaults to ``False``.
257306
id: Optional[:class:`int`]
258307
The select menu's ID.
308+
default_values: Optional[Sequence[Union[:class:`discord.SelectDefaultValue`, :class:`discord.abc.Snowflake`]]]
309+
The default values of this select. Only applicable if :attr:`.select_type` is not :attr:`discord.ComponentType.string_select`.
310+
311+
These can be either :class:`discord.SelectDefaultValue` instances or models, which will be converted into :class:`discord.SelectDefaultValue`
312+
instances.
259313
"""
260314

261315
select = Select(
@@ -268,6 +322,7 @@ def add_select(
268322
channel_types=channel_types or [],
269323
disabled=disabled,
270324
id=id,
325+
default_values=default_values
271326
)
272327

273328
return self.add_item(select)

discord/ui/label.py

Lines changed: 56 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
from __future__ import annotations
22

33
from typing import TYPE_CHECKING, Iterator, TypeVar
4+
from collections.abc import Sequence
45

56
from ..components import Label as LabelComponent
6-
from ..components import SelectOption, _component_factory
7+
from ..components import SelectOption, SelectDefaultValue, _component_factory
78
from ..enums import ButtonStyle, ChannelType, ComponentType, InputTextStyle
89
from ..utils import find, get
910
from .button import Button
@@ -184,6 +185,53 @@ def set_input_text(
184185

185186
return self.set_item(text)
186187

188+
@overload
189+
def set_select(
190+
self,
191+
select_type: Literal[ComponentType.string_select] = ...,
192+
*,
193+
custom_id: str | None = ...,
194+
placeholder: str | None = ...,
195+
min_values: int = ...,
196+
max_values: int = ...,
197+
options: list[SelectOption] | None = ...,
198+
required: bool = ...,
199+
id: int | None = ...,
200+
) -> None: ...
201+
202+
@overload
203+
def set_select(
204+
self,
205+
select_type: Literal[ComponentType.channel_select] = ...,
206+
*,
207+
custom_id: str | None = ...,
208+
placeholder: str | None = ...,
209+
min_values: int = ...,
210+
max_values: int = ...,
211+
channel_types: list[ChannelType] | None = ...,
212+
required: bool = ...,
213+
id: int | None = ...,
214+
default_values: Sequence[SelectDefaultValue] | None = ...,
215+
) -> None: ...
216+
217+
@overload
218+
def set_select(
219+
self,
220+
select_type: Literal[
221+
ComponentType.user_select,
222+
ComponentType.role_select,
223+
ComponentType.mentionable_select,
224+
] = ...,
225+
*,
226+
custom_id: str | None = ...,
227+
placeholder: str | None = ...,
228+
min_values: int = ...,
229+
max_values: int = ...,
230+
required: bool = ...,
231+
id: int | None = ...,
232+
default_values: Sequence[SelectDefaultValue] | None = ...,
233+
) -> None: ...
234+
187235
def set_select(
188236
self,
189237
select_type: ComponentType = ComponentType.string_select,
@@ -196,6 +244,7 @@ def set_select(
196244
channel_types: list[ChannelType] | None = None,
197245
required: bool = True,
198246
id: int | None = None,
247+
default_values: Sequence[SelectDefaultValue] | None = ...,
199248
) -> Self:
200249
"""Set this label's item to a select menu.
201250
@@ -227,6 +276,11 @@ def set_select(
227276
Whether the select is required or not. Defaults to ``True``.
228277
id: Optional[:class:`int`]
229278
The select menu's ID.
279+
default_values: Optional[Sequence[Union[:class:`discord.SelectDefaultValue`, :class:`discord.abc.Snowflake`]]]
280+
The default values of this select. Only applicable if :attr:`.select_type` is not :attr:`discord.ComponentType.string_select`.
281+
282+
These can be either :class:`discord.SelectDefaultValue` instances or models, which will be converted into :class:`discord.SelectDefaultValue`
283+
instances.
230284
"""
231285

232286
select = Select(
@@ -239,6 +293,7 @@ def set_select(
239293
channel_types=channel_types or [],
240294
required=required,
241295
id=id,
296+
default_values=default_values
242297
)
243298

244299
return self.set_item(select)

discord/ui/select.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,11 +134,11 @@ class Select(Generic[V, ST], Item[V]):
134134
rows. By default, items are arranged automatically into those 5 rows. If you'd
135135
like to control the relative positioning of the row then passing an index is advised.
136136
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
137-
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
137+
ordering. The row number must be between 0 and 4 (i.e. zero indexed). Does not work in :class:`ActionRow` or :class:`Label`.
138138
id: Optional[:class:`int`]
139139
The select menu's ID.
140140
required: Optional[:class:`bool`]
141-
Whether the select is required or not. Only useable in modals. Defaults to ``True`` in modals.
141+
Whether the select is required or not. Only useable when added to :class:`Label` for modals. Defaults to ``True`` in modals.
142142
143143
.. versionadded:: 2.7
144144
default_values: Optional[Sequence[Union[:class:`discord.SelectDefaultValue`, :class:`discord.abc.Snowflake`]]]

0 commit comments

Comments
 (0)