Adding all files

This commit is contained in:
2026-02-03 20:32:43 +02:00
parent 2588d10ba0
commit 77b70b600f
1457 changed files with 184865 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
# SPDX-License-Identifier: MIT
"""disnake.ui.select
~~~~~~~~~~~~~~~~~~
Select Menu UI Kit Types
:copyright: (c) 2021-present Disnake Development
:license: MIT, see LICENSE for more details.
"""
from . import base, channel, mentionable, role, string, user
from .base import *
from .channel import *
from .mentionable import *
from .role import *
from .string import *
from .user import *
__all__ = []
__all__.extend(base.__all__)
__all__.extend(channel.__all__)
__all__.extend(mentionable.__all__)
__all__.extend(role.__all__)
__all__.extend(string.__all__)
__all__.extend(user.__all__)

View File

@@ -0,0 +1,278 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
import os
from abc import ABC, abstractmethod
from typing import (
TYPE_CHECKING,
Callable,
ClassVar,
Generic,
List,
Mapping,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
Union,
)
from ...components import AnySelectMenu, SelectDefaultValue
from ...enums import ComponentType, SelectDefaultValueType
from ...object import Object
from ...utils import MISSING, humanize_list, iscoroutinefunction
from ..item import DecoratedItem, Item
__all__ = ("BaseSelect",)
if TYPE_CHECKING:
from typing_extensions import ParamSpec, Self
from ...abc import Snowflake
from ...interactions import MessageInteraction
from ..item import ItemCallbackType
from ..view import View
else:
ParamSpec = TypeVar
S_co = TypeVar("S_co", bound="BaseSelect", covariant=True)
V_co = TypeVar("V_co", bound="Optional[View]", covariant=True)
SelectMenuT = TypeVar("SelectMenuT", bound=AnySelectMenu)
SelectValueT = TypeVar("SelectValueT")
P = ParamSpec("P")
SelectDefaultValueMultiInputType = Union[SelectValueT, SelectDefaultValue]
# almost the same as above, but with `Object`; used for selects where the type isn't ambiguous (i.e. all except mentionable select)
SelectDefaultValueInputType = Union[SelectDefaultValueMultiInputType[SelectValueT], Object]
class BaseSelect(Generic[SelectMenuT, SelectValueT, V_co], Item[V_co], ABC):
"""Represents an abstract UI select menu.
This is usually represented as a drop down menu.
This isn't meant to be used directly, instead use one of the concrete select menu types:
- :class:`disnake.ui.StringSelect`
- :class:`disnake.ui.UserSelect`
- :class:`disnake.ui.RoleSelect`
- :class:`disnake.ui.MentionableSelect`
- :class:`disnake.ui.ChannelSelect`
.. versionadded:: 2.7
"""
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
"placeholder",
"min_values",
"max_values",
"disabled",
"required",
)
# We have to set this to MISSING in order to overwrite the abstract property from UIComponent
_underlying: SelectMenuT = MISSING
# Subclasses are expected to set this
_default_value_type_map: ClassVar[Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]]
def __init__(
self,
underlying_type: Type[SelectMenuT],
component_type: ComponentType,
*,
custom_id: str,
placeholder: Optional[str],
min_values: int,
max_values: int,
disabled: bool,
default_values: Optional[Sequence[SelectDefaultValueInputType[SelectValueT]]],
required: bool,
id: int,
row: Optional[int],
) -> None:
super().__init__()
self._selected_values: List[SelectValueT] = []
self._provided_custom_id = custom_id is not MISSING
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
self._underlying = underlying_type._raw_construct(
type=component_type,
id=id,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=self._transform_default_values(default_values) if default_values else [],
required=required,
)
self.row = row
@property
def custom_id(self) -> str:
""":class:`str`: The ID of the select menu that gets received during an interaction."""
return self._underlying.custom_id
@custom_id.setter
def custom_id(self, value: str) -> None:
if not isinstance(value, str):
raise TypeError("custom_id must be None or str")
self._underlying.custom_id = value
@property
def placeholder(self) -> Optional[str]:
"""Optional[:class:`str`]: The placeholder text that is shown if nothing is selected, if any."""
return self._underlying.placeholder
@placeholder.setter
def placeholder(self, value: Optional[str]) -> None:
if value is not None and not isinstance(value, str):
raise TypeError("placeholder must be None or str")
self._underlying.placeholder = value
@property
def min_values(self) -> int:
""":class:`int`: The minimum number of items that must be chosen for this select menu."""
return self._underlying.min_values
@min_values.setter
def min_values(self, value: int) -> None:
self._underlying.min_values = int(value)
@property
def max_values(self) -> int:
""":class:`int`: The maximum number of items that must be chosen for this select menu."""
return self._underlying.max_values
@max_values.setter
def max_values(self, value: int) -> None:
self._underlying.max_values = int(value)
@property
def disabled(self) -> bool:
""":class:`bool`: Whether the select menu is disabled."""
return self._underlying.disabled
@disabled.setter
def disabled(self, value: bool) -> None:
self._underlying.disabled = bool(value)
@property
def default_values(self) -> List[SelectDefaultValue]:
"""List[:class:`.SelectDefaultValue`]: The list of values that are selected by default.
Only available for auto-populated select menus.
"""
return self._underlying.default_values
@default_values.setter
def default_values(
self, value: Optional[Sequence[SelectDefaultValueInputType[SelectValueT]]]
) -> None:
self._underlying.default_values = self._transform_default_values(value) if value else []
@property
def required(self) -> bool:
""":class:`bool`: Whether the select menu is required.
Only applies to components in modals.
.. versionadded:: 2.11
"""
return self._underlying.required
@required.setter
def required(self, value: bool) -> None:
self._underlying.required = bool(value)
@property
def values(self) -> List[SelectValueT]:
return self._selected_values
@property
def width(self) -> int:
return 5
def refresh_component(self, component: SelectMenuT) -> None:
self._underlying = component
def refresh_state(self, interaction: MessageInteraction) -> None:
self._selected_values = interaction.resolved_values # type: ignore
@classmethod
@abstractmethod
def from_component(cls, component: SelectMenuT) -> Self:
raise NotImplementedError
def is_dispatchable(self) -> bool:
"""Whether the select menu is dispatchable. This will always return ``True``.
:return type: :class:`bool`
"""
return True
@classmethod
def _transform_default_values(
cls, values: Sequence[SelectDefaultValueInputType[SelectValueT]]
) -> List[SelectDefaultValue]:
result: List[SelectDefaultValue] = []
for value in values:
# If we have a SelectDefaultValue, just use it as-is
if isinstance(value, SelectDefaultValue):
if value.type not in cls._default_value_type_map:
allowed_types = [str(t) for t in cls._default_value_type_map]
raise ValueError(
f"SelectDefaultValue.type should be {humanize_list(allowed_types, 'or')}, not {value.type}"
)
result.append(value)
continue
# Otherwise, look through the list of allowed input types and
# get the associated SelectDefaultValueType
for (
value_type, # noqa: B007 # we use value_type outside of the loop
types,
) in cls._default_value_type_map.items():
if isinstance(value, types):
break
else:
allowed_types = [
t.__name__ for ts in cls._default_value_type_map.values() for t in ts
]
allowed_types.append(SelectDefaultValue.__name__)
raise TypeError(
f"Expected type of default value to be {humanize_list(allowed_types, 'or')}, not {type(value)!r}"
)
result.append(SelectDefaultValue(value.id, value_type))
return result
def _create_decorator(
# FIXME(3.0): rename `cls` parameter to more closely represent any callable argument type
cls: Callable[P, S_co],
/,
*args: P.args,
**kwargs: P.kwargs,
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
if args:
# the `*args` def above is just to satisfy the typechecker
raise RuntimeError("expected no *args")
if not callable(cls):
raise TypeError("cls argument must be callable")
def decorator(func: ItemCallbackType[V_co, S_co]) -> DecoratedItem[S_co]:
if not iscoroutinefunction(func):
raise TypeError("select function must be a coroutine function")
func.__discord_ui_model_type__ = cls
func.__discord_ui_model_kwargs__ = kwargs
return func # type: ignore
return decorator

View File

@@ -0,0 +1,288 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
List,
Mapping,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
overload,
)
from ...abc import GuildChannel, Snowflake
from ...channel import DMChannel, GroupChannel, PartialMessageable
from ...components import ChannelSelectMenu
from ...enums import ChannelType, ComponentType, SelectDefaultValueType
from ...object import Object
from ...threads import Thread
from ...utils import MISSING
from .base import BaseSelect, P, SelectDefaultValueInputType, V_co, _create_decorator
if TYPE_CHECKING:
from typing_extensions import Self
from ...abc import AnyChannel
from ..item import DecoratedItem, ItemCallbackType
__all__ = (
"ChannelSelect",
"channel_select",
)
class ChannelSelect(BaseSelect[ChannelSelectMenu, "AnyChannel", V_co]):
"""Represents a UI channel select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use :attr:`.values`.
.. versionadded:: 2.7
Parameters
----------
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
If not given then one is generated for you.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled.
channel_types: Optional[List[:class:`.ChannelType`]]
The list of channel types that can be selected in this select menu.
Defaults to all types (i.e. ``None``).
default_values: Optional[Sequence[Union[:class:`.abc.GuildChannel`, :class:`.Thread`, :class:`.abc.PrivateChannel`, :class:`.PartialMessageable`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (channels) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
required: :class:`bool`
Whether the select menu is required. Only applies to components in modals.
Defaults to ``True``.
.. versionadded:: 2.11
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Attributes
----------
values: List[Union[:class:`.abc.GuildChannel`, :class:`.Thread`, :class:`.abc.PrivateChannel`, :class:`.PartialMessageable`]]
A list of channels that have been selected by the user.
"""
__repr_attributes__: ClassVar[Tuple[str, ...]] = (
*BaseSelect.__repr_attributes__,
"channel_types",
)
_default_value_type_map: ClassVar[
Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]
] = {
SelectDefaultValueType.channel: (
GuildChannel,
Thread,
DMChannel,
GroupChannel,
PartialMessageable,
Object,
),
}
@overload
def __init__(
self: ChannelSelect[None],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
channel_types: Optional[List[ChannelType]] = None,
default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
@overload
def __init__(
self: ChannelSelect[V_co],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
channel_types: Optional[List[ChannelType]] = None,
default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
def __init__(
self,
*,
custom_id: str = MISSING,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
channel_types: Optional[List[ChannelType]] = None,
default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None:
super().__init__(
ChannelSelectMenu,
ComponentType.channel_select,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=default_values,
required=required,
id=id,
row=row,
)
self._underlying.channel_types = channel_types or None
@classmethod
def from_component(cls, component: ChannelSelectMenu) -> Self:
return cls(
custom_id=component.custom_id,
placeholder=component.placeholder,
min_values=component.min_values,
max_values=component.max_values,
disabled=component.disabled,
channel_types=component.channel_types,
default_values=component.default_values,
required=component.required,
id=component.id,
row=None,
)
@property
def channel_types(self) -> Optional[List[ChannelType]]:
"""Optional[List[:class:`disnake.ChannelType`]]: A list of channel types that can be selected in this select menu."""
return self._underlying.channel_types
@channel_types.setter
def channel_types(self, value: Optional[List[ChannelType]]) -> None:
if value is not None:
if not isinstance(value, list):
raise TypeError("channel_types must be a list of ChannelType")
if not all(isinstance(obj, ChannelType) for obj in value):
raise TypeError("all list items must be ChannelType")
self._underlying.channel_types = value
S_co = TypeVar("S_co", bound="ChannelSelect", covariant=True)
@overload
def channel_select(
*,
placeholder: Optional[str] = None,
custom_id: str = ...,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
channel_types: Optional[List[ChannelType]] = None,
default_values: Optional[Sequence[SelectDefaultValueInputType[AnyChannel]]] = None,
id: int = 0,
row: Optional[int] = None,
) -> Callable[
[ItemCallbackType[V_co, ChannelSelect[V_co]]], DecoratedItem[ChannelSelect[V_co]]
]: ...
@overload
def channel_select(
cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ...
def channel_select(
cls: Callable[..., S_co] = ChannelSelect[Any], **kwargs: Any
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
"""A decorator that attaches a channel select menu to a component.
The function being decorated should have three parameters, ``self`` representing
the :class:`disnake.ui.View`, the :class:`disnake.ui.ChannelSelect` that was
interacted with, and the :class:`disnake.MessageInteraction`.
In order to get the selected items that the user has chosen within the callback
use :attr:`ChannelSelect.values`.
.. versionadded:: 2.7
Parameters
----------
cls: Callable[..., :class:`ChannelSelect`]
A callable (may be a :class:`ChannelSelect` subclass) to create a new instance of this component.
If provided, the other parameters described below do not apply.
Instead, this decorator will accept the same keywords as the passed callable/class does.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled. Defaults to ``False``.
channel_types: Optional[List[:class:`.ChannelType`]]
The list of channel types that can be selected in this select menu.
Defaults to all types (i.e. ``None``).
default_values: Optional[Sequence[Union[:class:`.abc.GuildChannel`, :class:`.Thread`, :class:`.abc.PrivateChannel`, :class:`.PartialMessageable`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (channels) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
"""
return _create_decorator(cls, **kwargs)

View File

@@ -0,0 +1,261 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Mapping,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from ...abc import Snowflake
from ...components import MentionableSelectMenu
from ...enums import ComponentType, SelectDefaultValueType
from ...member import Member
from ...role import Role
from ...user import ClientUser, User
from ...utils import MISSING
from .base import BaseSelect, P, SelectDefaultValueMultiInputType, V_co, _create_decorator
if TYPE_CHECKING:
from typing_extensions import Self
from ..item import DecoratedItem, ItemCallbackType
__all__ = (
"MentionableSelect",
"mentionable_select",
)
class MentionableSelect(BaseSelect[MentionableSelectMenu, "Union[User, Member, Role]", V_co]):
"""Represents a UI mentionable (user/member/role) select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use :attr:`.values`.
.. versionadded:: 2.7
Parameters
----------
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
If not given then one is generated for you.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled.
default_values: Optional[Sequence[Union[:class:`~disnake.User`, :class:`.Member`, :class:`.Role`, :class:`.SelectDefaultValue`]]]
The list of values (users/roles) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
Note that unlike other select menu types, this does not support :class:`.Object`\\s due to ambiguities.
.. versionadded:: 2.10
required: :class:`bool`
Whether the select menu is required. Only applies to components in modals.
Defaults to ``True``.
.. versionadded:: 2.11
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Attributes
----------
values: List[Union[:class:`~disnake.User`, :class:`.Member`, :class:`.Role`]]
A list of users, members and/or roles that have been selected by the user.
"""
_default_value_type_map: ClassVar[
Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]
] = {
SelectDefaultValueType.user: (Member, User, ClientUser),
SelectDefaultValueType.role: (Role,),
}
@overload
def __init__(
self: MentionableSelect[None],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[
Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]]
] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
@overload
def __init__(
self: MentionableSelect[V_co],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[
Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]]
] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
def __init__(
self,
*,
custom_id: str = MISSING,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[
Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]]
] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None:
super().__init__(
MentionableSelectMenu,
ComponentType.mentionable_select,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=default_values,
required=required,
id=id,
row=row,
)
@classmethod
def from_component(cls, component: MentionableSelectMenu) -> Self:
return cls(
custom_id=component.custom_id,
placeholder=component.placeholder,
min_values=component.min_values,
max_values=component.max_values,
disabled=component.disabled,
default_values=component.default_values,
required=component.required,
id=component.id,
row=None,
)
S_co = TypeVar("S_co", bound="MentionableSelect", covariant=True)
@overload
def mentionable_select(
*,
placeholder: Optional[str] = None,
custom_id: str = ...,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[
Sequence[SelectDefaultValueMultiInputType[Union[User, Member, Role]]]
] = None,
id: int = 0,
row: Optional[int] = None,
) -> Callable[
[ItemCallbackType[V_co, MentionableSelect[V_co]]], DecoratedItem[MentionableSelect[V_co]]
]: ...
@overload
def mentionable_select(
cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ...
def mentionable_select(
cls: Callable[..., S_co] = MentionableSelect[Any], **kwargs: Any
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
"""A decorator that attaches a mentionable (user/member/role) select menu to a component.
The function being decorated should have three parameters, ``self`` representing
the :class:`disnake.ui.View`, the :class:`disnake.ui.MentionableSelect` that was
interacted with, and the :class:`disnake.MessageInteraction`.
In order to get the selected items that the user has chosen within the callback
use :attr:`MentionableSelect.values`.
.. versionadded:: 2.7
Parameters
----------
cls: Callable[..., :class:`MentionableSelect`]
A callable (may be a :class:`MentionableSelect` subclass) to create a new instance of this component.
If provided, the other parameters described below do not apply.
Instead, this decorator will accept the same keywords as the passed callable/class does.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled. Defaults to ``False``.
default_values: Optional[Sequence[Union[:class:`~disnake.User`, :class:`.Member`, :class:`.Role`, :class:`.SelectDefaultValue`]]]
The list of values (users/roles) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
Note that unlike other select menu types, this does not support :class:`.Object`\\s due to ambiguities.
.. versionadded:: 2.10
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
"""
return _create_decorator(cls, **kwargs)

View File

@@ -0,0 +1,244 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Mapping,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
overload,
)
from ...abc import Snowflake
from ...components import RoleSelectMenu
from ...enums import ComponentType, SelectDefaultValueType
from ...object import Object
from ...role import Role
from ...utils import MISSING
from .base import BaseSelect, P, SelectDefaultValueInputType, V_co, _create_decorator
if TYPE_CHECKING:
from typing_extensions import Self
from ..item import DecoratedItem, ItemCallbackType
__all__ = (
"RoleSelect",
"role_select",
)
class RoleSelect(BaseSelect[RoleSelectMenu, "Role", V_co]):
"""Represents a UI role select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use :attr:`.values`.
.. versionadded:: 2.7
Parameters
----------
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
If not given then one is generated for you.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled.
default_values: Optional[Sequence[Union[:class:`.Role`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (roles) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
required: :class:`bool`
Whether the select menu is required. Only applies to components in modals.
Defaults to ``True``.
.. versionadded:: 2.11
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Attributes
----------
values: List[:class:`.Role`]
A list of roles that have been selected by the user.
"""
_default_value_type_map: ClassVar[
Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]
] = {
SelectDefaultValueType.role: (Role, Object),
}
@overload
def __init__(
self: RoleSelect[None],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
@overload
def __init__(
self: RoleSelect[V_co],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
def __init__(
self,
*,
custom_id: str = MISSING,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None:
super().__init__(
RoleSelectMenu,
ComponentType.role_select,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=default_values,
required=required,
id=id,
row=row,
)
@classmethod
def from_component(cls, component: RoleSelectMenu) -> Self:
return cls(
custom_id=component.custom_id,
placeholder=component.placeholder,
min_values=component.min_values,
max_values=component.max_values,
disabled=component.disabled,
default_values=component.default_values,
required=component.required,
id=component.id,
row=None,
)
S_co = TypeVar("S_co", bound="RoleSelect", covariant=True)
@overload
def role_select(
*,
placeholder: Optional[str] = None,
custom_id: str = ...,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Role]]] = None,
id: int = 0,
row: Optional[int] = None,
) -> Callable[[ItemCallbackType[V_co, RoleSelect[V_co]]], DecoratedItem[RoleSelect[V_co]]]: ...
@overload
def role_select(
cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ...
def role_select(
cls: Callable[..., S_co] = RoleSelect[Any], **kwargs: Any
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
"""A decorator that attaches a role select menu to a component.
The function being decorated should have three parameters, ``self`` representing
the :class:`disnake.ui.View`, the :class:`disnake.ui.RoleSelect` that was
interacted with, and the :class:`disnake.MessageInteraction`.
In order to get the selected items that the user has chosen within the callback
use :attr:`RoleSelect.values`.
.. versionadded:: 2.7
Parameters
----------
cls: Callable[..., :class:`RoleSelect`]
A callable (may be a :class:`RoleSelect` subclass) to create a new instance of this component.
If provided, the other parameters described below do not apply.
Instead, this decorator will accept the same keywords as the passed callable/class does.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled. Defaults to ``False``.
default_values: Optional[Sequence[Union[:class:`.Role`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (roles) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
"""
return _create_decorator(cls, **kwargs)

View File

@@ -0,0 +1,358 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Dict,
List,
Mapping,
Optional,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from ...abc import Snowflake
from ...components import SelectOption, StringSelectMenu
from ...enums import ComponentType, SelectDefaultValueType
from ...utils import MISSING
from .base import BaseSelect, P, V_co, _create_decorator
if TYPE_CHECKING:
from typing_extensions import Self
from ...emoji import Emoji
from ...partial_emoji import PartialEmoji
from ..item import DecoratedItem, ItemCallbackType
__all__ = (
"StringSelect",
"Select",
"string_select",
"select",
)
SelectOptionInput = Union[List[SelectOption], List[str], Dict[str, str]]
def _parse_select_options(options: SelectOptionInput) -> List[SelectOption]:
if isinstance(options, dict):
return [SelectOption(label=key, value=val) for key, val in options.items()]
return [opt if isinstance(opt, SelectOption) else SelectOption(label=opt) for opt in options]
class StringSelect(BaseSelect[StringSelectMenu, str, V_co]):
"""Represents a UI string select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use :attr:`.values`.
.. versionadded:: 2.0
.. versionchanged:: 2.7
Renamed from ``Select`` to ``StringSelect``.
Parameters
----------
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
If not given then one is generated for you.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled.
options: Union[List[:class:`disnake.SelectOption`], List[:class:`str`], Dict[:class:`str`, :class:`str`]]
A list of options that can be selected in this menu. Use explicit :class:`.SelectOption`\\s
for fine-grained control over the options. Alternatively, a list of strings will be treated
as a list of labels, and a dict will be treated as a mapping of labels to values.
.. versionchanged:: 2.5
Now also accepts a list of str or a dict of str to str, which are then appropriately parsed as
:class:`.SelectOption` labels and values.
required: :class:`bool`
Whether the select menu is required. Only applies to components in modals.
Defaults to ``True``.
.. versionadded:: 2.11
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Attributes
----------
values: List[:class:`str`]
A list of values that have been selected by the user.
"""
__repr_attributes__: ClassVar[Tuple[str, ...]] = (*BaseSelect.__repr_attributes__, "options")
# In practice this should never be used by anything, might as well have it anyway though.
_default_value_type_map: ClassVar[
Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]
] = {}
@overload
def __init__(
self: StringSelect[None],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
options: SelectOptionInput = ...,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
@overload
def __init__(
self: StringSelect[V_co],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
options: SelectOptionInput = ...,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
def __init__(
self,
*,
custom_id: str = MISSING,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
options: SelectOptionInput = MISSING,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None:
super().__init__(
StringSelectMenu,
ComponentType.string_select,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=None,
required=required,
id=id,
row=row,
)
self._underlying.options = [] if options is MISSING else _parse_select_options(options)
@classmethod
def from_component(cls, component: StringSelectMenu) -> Self:
return cls(
custom_id=component.custom_id,
placeholder=component.placeholder,
min_values=component.min_values,
max_values=component.max_values,
disabled=component.disabled,
options=component.options,
required=component.required,
id=component.id,
row=None,
)
@property
def options(self) -> List[SelectOption]:
"""List[:class:`disnake.SelectOption`]: A list of options that can be selected in this select menu."""
return self._underlying.options
@options.setter
def options(self, value: List[SelectOption]) -> None:
if not isinstance(value, list):
raise TypeError("options must be a list of SelectOption")
if not all(isinstance(obj, SelectOption) for obj in value):
raise TypeError("all list items must subclass SelectOption")
self._underlying.options = value
def add_option(
self,
*,
label: str,
value: str = MISSING,
description: Optional[str] = None,
emoji: Optional[Union[str, Emoji, PartialEmoji]] = None,
default: bool = False,
) -> None:
"""Adds an option to the select menu.
To append a pre-existing :class:`.SelectOption` use the
:meth:`append_option` method instead.
Parameters
----------
label: :class:`str`
The label of the option. This is displayed to users.
Can only be up to 100 characters.
value: :class:`str`
The value of the option. This is not displayed to users.
If not given, defaults to the label. Can only be up to 100 characters.
description: Optional[:class:`str`]
An additional description of the option, if any.
Can only be up to 100 characters.
emoji: Optional[Union[:class:`str`, :class:`.Emoji`, :class:`.PartialEmoji`]]
The emoji of the option, if available. This can either be a string representing
the custom or unicode emoji or an instance of :class:`.PartialEmoji` or :class:`.Emoji`.
default: :class:`bool`
Whether this option is selected by default.
Raises
------
ValueError
The number of options exceeds 25.
"""
option = SelectOption(
label=label,
value=value,
description=description,
emoji=emoji,
default=default,
)
self.append_option(option)
def append_option(self, option: SelectOption) -> None:
"""Appends an option to the select menu.
Parameters
----------
option: :class:`disnake.SelectOption`
The option to append to the select menu.
Raises
------
ValueError
The number of options exceeds 25.
"""
if len(self._underlying.options) >= 25:
raise ValueError("maximum number of options already provided")
self._underlying.options.append(option)
Select = StringSelect # backwards compatibility
S_co = TypeVar("S_co", bound="StringSelect", covariant=True)
@overload
def string_select(
*,
placeholder: Optional[str] = None,
custom_id: str = ...,
min_values: int = 1,
max_values: int = 1,
options: SelectOptionInput = ...,
disabled: bool = False,
id: int = 0,
row: Optional[int] = None,
) -> Callable[[ItemCallbackType[V_co, StringSelect[V_co]]], DecoratedItem[StringSelect[V_co]]]: ...
@overload
def string_select(
cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ...
def string_select(
cls: Callable[..., S_co] = StringSelect[Any], **kwargs: Any
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
"""A decorator that attaches a string select menu to a component.
The function being decorated should have three parameters, ``self`` representing
the :class:`disnake.ui.View`, the :class:`disnake.ui.StringSelect` that was
interacted with, and the :class:`disnake.MessageInteraction`.
In order to get the selected items that the user has chosen within the callback
use :attr:`StringSelect.values`.
.. versionchanged:: 2.7
Renamed from ``select`` to ``string_select``.
Parameters
----------
cls: Callable[..., :class:`StringSelect`]
A callable (may be a :class:`StringSelect` subclass) to create a new instance of this component.
If provided, the other parameters described below do not apply.
Instead, this decorator will accept the same keywords as the passed callable/class does.
.. versionadded:: 2.6
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
options: Union[List[:class:`disnake.SelectOption`], List[:class:`str`], Dict[:class:`str`, :class:`str`]]
A list of options that can be selected in this menu. Use explicit :class:`.SelectOption`\\s
for fine-grained control over the options. Alternatively, a list of strings will be treated
as a list of labels, and a dict will be treated as a mapping of labels to values.
.. versionchanged:: 2.5
Now also accepts a list of str or a dict of str to str, which are then appropriately parsed as
:class:`.SelectOption` labels and values.
disabled: :class:`bool`
Whether the select is disabled. Defaults to ``False``.
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
"""
return _create_decorator(cls, **kwargs)
select = string_select # backwards compatibility

View File

@@ -0,0 +1,246 @@
# SPDX-License-Identifier: MIT
from __future__ import annotations
from typing import (
TYPE_CHECKING,
Any,
Callable,
ClassVar,
Mapping,
Optional,
Sequence,
Tuple,
Type,
TypeVar,
Union,
overload,
)
from ...abc import Snowflake
from ...components import UserSelectMenu
from ...enums import ComponentType, SelectDefaultValueType
from ...member import Member
from ...object import Object
from ...user import ClientUser, User
from ...utils import MISSING
from .base import BaseSelect, P, SelectDefaultValueInputType, V_co, _create_decorator
if TYPE_CHECKING:
from typing_extensions import Self
from ..item import DecoratedItem, ItemCallbackType
__all__ = (
"UserSelect",
"user_select",
)
class UserSelect(BaseSelect[UserSelectMenu, "Union[User, Member]", V_co]):
"""Represents a UI user select menu.
This is usually represented as a drop down menu.
In order to get the selected items that the user has chosen, use :attr:`.values`.
.. versionadded:: 2.7
Parameters
----------
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
If not given then one is generated for you.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled.
default_values: Optional[Sequence[Union[:class:`~disnake.User`, :class:`.Member`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (users/members) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
required: :class:`bool`
Whether the select menu is required. Only applies to components in modals.
Defaults to ``True``.
.. versionadded:: 2.11
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
Attributes
----------
values: List[:class:`~disnake.User`, :class:`.Member`]
A list of users/members that have been selected by the user.
"""
_default_value_type_map: ClassVar[
Mapping[SelectDefaultValueType, Tuple[Type[Snowflake], ...]]
] = {
SelectDefaultValueType.user: (Member, User, ClientUser, Object),
}
@overload
def __init__(
self: UserSelect[None],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
@overload
def __init__(
self: UserSelect[V_co],
*,
custom_id: str = ...,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None: ...
def __init__(
self,
*,
custom_id: str = MISSING,
placeholder: Optional[str] = None,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None,
required: bool = True,
id: int = 0,
row: Optional[int] = None,
) -> None:
super().__init__(
UserSelectMenu,
ComponentType.user_select,
custom_id=custom_id,
placeholder=placeholder,
min_values=min_values,
max_values=max_values,
disabled=disabled,
default_values=default_values,
required=required,
id=id,
row=row,
)
@classmethod
def from_component(cls, component: UserSelectMenu) -> Self:
return cls(
custom_id=component.custom_id,
placeholder=component.placeholder,
min_values=component.min_values,
max_values=component.max_values,
disabled=component.disabled,
default_values=component.default_values,
required=component.required,
id=component.id,
row=None,
)
S_co = TypeVar("S_co", bound="UserSelect", covariant=True)
@overload
def user_select(
*,
placeholder: Optional[str] = None,
custom_id: str = ...,
min_values: int = 1,
max_values: int = 1,
disabled: bool = False,
default_values: Optional[Sequence[SelectDefaultValueInputType[Union[User, Member]]]] = None,
id: int = 0,
row: Optional[int] = None,
) -> Callable[[ItemCallbackType[V_co, UserSelect[V_co]]], DecoratedItem[UserSelect[V_co]]]: ...
@overload
def user_select(
cls: Callable[P, S_co], *_: P.args, **kwargs: P.kwargs
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]: ...
def user_select(
cls: Callable[..., S_co] = UserSelect[Any], **kwargs: Any
) -> Callable[[ItemCallbackType[V_co, S_co]], DecoratedItem[S_co]]:
"""A decorator that attaches a user select menu to a component.
The function being decorated should have three parameters, ``self`` representing
the :class:`disnake.ui.View`, the :class:`disnake.ui.UserSelect` that was
interacted with, and the :class:`disnake.MessageInteraction`.
In order to get the selected items that the user has chosen within the callback
use :attr:`UserSelect.values`.
.. versionadded:: 2.7
Parameters
----------
cls: Callable[..., :class:`UserSelect`]
A callable (may be a :class:`UserSelect` subclass) to create a new instance of this component.
If provided, the other parameters described below do not apply.
Instead, this decorator will accept the same keywords as the passed callable/class does.
placeholder: Optional[:class:`str`]
The placeholder text that is shown if nothing is selected, if any.
custom_id: :class:`str`
The ID of the select menu that gets received during an interaction.
It is recommended not to set this parameter to prevent conflicts.
min_values: :class:`int`
The minimum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
max_values: :class:`int`
The maximum number of items that must be chosen for this select menu.
Defaults to 1 and must be between 1 and 25.
disabled: :class:`bool`
Whether the select is disabled. Defaults to ``False``.
default_values: Optional[Sequence[Union[:class:`~disnake.User`, :class:`.Member`, :class:`.SelectDefaultValue`, :class:`.Object`]]]
The list of values (users/members) that are selected by default.
If set, the number of items must be within the bounds set by ``min_values`` and ``max_values``.
.. versionadded:: 2.10
id: :class:`int`
The numeric identifier for the component. Must be unique within the message.
If set to ``0`` (the default) when sending a component, the API will assign
sequential identifiers to the components in the message.
.. versionadded:: 2.11
row: Optional[:class:`int`]
The relative row this select menu belongs to. A Discord component can only have 5
rows. By default, items are arranged automatically into those 5 rows. If you'd
like to control the relative positioning of the row then passing an index is advised.
For example, row=1 will show up before row=2. Defaults to ``None``, which is automatic
ordering. The row number must be between 0 and 4 (i.e. zero indexed).
"""
return _create_decorator(cls, **kwargs)