diff options
| author | Lucas Hardt <[email protected]> | 2021-07-29 01:58:39 +0200 |
|---|---|---|
| committer | GitHub <[email protected]> | 2021-07-28 19:58:39 -0400 |
| commit | ca9b371982637236f34383cdfffbb4fd8fa40f95 (patch) | |
| tree | 390a94e4f1856a0ce5fbc6946c58a4c924b47635 /discord/ui/select.py | |
| parent | Allow callables in abc.Connectable.Connect (diff) | |
| download | discord.py-ca9b371982637236f34383cdfffbb4fd8fa40f95.tar.xz discord.py-ca9b371982637236f34383cdfffbb4fd8fa40f95.zip | |
Add support for discord.ui.Select.disabled
Diffstat (limited to 'discord/ui/select.py')
| -rw-r--r-- | discord/ui/select.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/discord/ui/select.py b/discord/ui/select.py index e8fe68ad..1a0d7388 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -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 @@ -241,6 +247,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.""" return self._selected_values @@ -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 |