mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-06-03 10:32:42 +00:00
Add support for discord.ui.Select.disabled
This commit is contained in:
parent
41e2d3c637
commit
ca9b371982
@ -226,6 +226,8 @@ class SelectMenu(Component):
|
||||
Defaults to 1 and must be between 1 and 25.
|
||||
options: List[:class:`SelectOption`]
|
||||
A list of options that can be selected in this menu.
|
||||
disabled: :class:`bool`
|
||||
Whether the select is disabled or not.
|
||||
"""
|
||||
|
||||
__slots__: Tuple[str, ...] = (
|
||||
@ -234,6 +236,7 @@ class SelectMenu(Component):
|
||||
'min_values',
|
||||
'max_values',
|
||||
'options',
|
||||
'disabled',
|
||||
)
|
||||
|
||||
__repr_info__: ClassVar[Tuple[str, ...]] = __slots__
|
||||
@ -245,6 +248,7 @@ class SelectMenu(Component):
|
||||
self.min_values: int = data.get('min_values', 1)
|
||||
self.max_values: int = data.get('max_values', 1)
|
||||
self.options: List[SelectOption] = [SelectOption.from_dict(option) for option in data.get('options', [])]
|
||||
self.disabled: bool = data.get('disabled', False)
|
||||
|
||||
def to_dict(self) -> SelectMenuPayload:
|
||||
payload: SelectMenuPayload = {
|
||||
@ -253,6 +257,7 @@ class SelectMenu(Component):
|
||||
'min_values': self.min_values,
|
||||
'max_values': self.max_values,
|
||||
'options': [op.to_dict() for op in self.options],
|
||||
'disabled': self.disabled,
|
||||
}
|
||||
|
||||
if self.placeholder:
|
||||
|
@ -53,6 +53,7 @@ class _SelectMenuOptional(TypedDict, total=False):
|
||||
placeholder: str
|
||||
min_values: int
|
||||
max_values: int
|
||||
disabled: bool
|
||||
|
||||
|
||||
class _SelectOptionsOptional(TypedDict, total=False):
|
||||
|
@ -78,6 +78,8 @@ class Select(Item[V]):
|
||||
Defaults to 1 and must be between 1 and 25.
|
||||
options: List[:class:`discord.SelectOption`]
|
||||
A list of options that can be selected in this menu.
|
||||
disabled: :class:`bool`
|
||||
Whether the select is disabled or not.
|
||||
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
|
||||
@ -91,6 +93,7 @@ class Select(Item[V]):
|
||||
'min_values',
|
||||
'max_values',
|
||||
'options',
|
||||
'disabled',
|
||||
)
|
||||
|
||||
def __init__(
|
||||
@ -101,8 +104,10 @@ class Select(Item[V]):
|
||||
min_values: int = 1,
|
||||
max_values: int = 1,
|
||||
options: List[SelectOption] = MISSING,
|
||||
disabled: bool = False,
|
||||
row: Optional[int] = None,
|
||||
) -> None:
|
||||
super().__init__()
|
||||
self._selected_values: List[str] = []
|
||||
self._provided_custom_id = custom_id is not MISSING
|
||||
custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id
|
||||
@ -114,6 +119,7 @@ class Select(Item[V]):
|
||||
min_values=min_values,
|
||||
max_values=max_values,
|
||||
options=options,
|
||||
disabled=disabled,
|
||||
)
|
||||
self.row = row
|
||||
|
||||
@ -240,6 +246,15 @@ class Select(Item[V]):
|
||||
|
||||
self._underlying.options.append(option)
|
||||
|
||||
@property
|
||||
def disabled(self) -> bool:
|
||||
""":class:`bool`: Whether the select is disabled or not."""
|
||||
return self._underlying.disabled
|
||||
|
||||
@disabled.setter
|
||||
def disabled(self, value: bool):
|
||||
self._underlying.disabled = bool(value)
|
||||
|
||||
@property
|
||||
def values(self) -> List[str]:
|
||||
"""List[:class:`str`]: A list of values that have been selected by the user."""
|
||||
@ -267,6 +282,7 @@ class Select(Item[V]):
|
||||
min_values=component.min_values,
|
||||
max_values=component.max_values,
|
||||
options=component.options,
|
||||
disabled=component.disabled,
|
||||
row=None,
|
||||
)
|
||||
|
||||
@ -285,6 +301,7 @@ def select(
|
||||
min_values: int = 1,
|
||||
max_values: int = 1,
|
||||
options: List[SelectOption] = MISSING,
|
||||
disabled: bool = False,
|
||||
row: Optional[int] = None,
|
||||
) -> Callable[[ItemCallbackType], ItemCallbackType]:
|
||||
"""A decorator that attaches a select menu to a component.
|
||||
@ -317,11 +334,13 @@ def select(
|
||||
Defaults to 1 and must be between 1 and 25.
|
||||
options: List[:class:`discord.SelectOption`]
|
||||
A list of options that can be selected in this menu.
|
||||
disabled: :class:`bool`
|
||||
Whether the select is disabled or not. Defaults to ``False``.
|
||||
"""
|
||||
|
||||
def decorator(func: ItemCallbackType) -> ItemCallbackType:
|
||||
if not inspect.iscoroutinefunction(func):
|
||||
raise TypeError('button function must be a coroutine function')
|
||||
raise TypeError('select function must be a coroutine function')
|
||||
|
||||
func.__discord_ui_model_type__ = Select
|
||||
func.__discord_ui_model_kwargs__ = {
|
||||
@ -331,6 +350,7 @@ def select(
|
||||
'min_values': min_values,
|
||||
'max_values': max_values,
|
||||
'options': options,
|
||||
'disabled': disabled,
|
||||
}
|
||||
return func
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user