diff options
| author | Rapptz <[email protected]> | 2021-05-29 23:58:37 -0400 |
|---|---|---|
| committer | Rapptz <[email protected]> | 2021-05-29 23:58:37 -0400 |
| commit | 7bd1211b36dc256e064b5030b56007c1eee2b5df (patch) | |
| tree | cf206c7b952d1c31747ceb209e2791a4ceb8f415 /discord/ui/select.py | |
| parent | Fix Messageable.send overload to take view parameters (diff) | |
| download | discord.py-7bd1211b36dc256e064b5030b56007c1eee2b5df.tar.xz discord.py-7bd1211b36dc256e064b5030b56007c1eee2b5df.zip | |
Rework item grouping behaviour to take into consideration weights
This also renames `group` into `row`
Diffstat (limited to 'discord/ui/select.py')
| -rw-r--r-- | discord/ui/select.py | 32 |
1 files changed, 21 insertions, 11 deletions
diff --git a/discord/ui/select.py b/discord/ui/select.py index cbbee3bc..e37b55c0 100644 --- a/discord/ui/select.py +++ b/discord/ui/select.py @@ -75,6 +75,12 @@ 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. + 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 cannot be negative or greater than 5. """ __item_repr_attributes__: Tuple[str, ...] = ( @@ -92,7 +98,7 @@ class Select(Item[V]): min_values: int = 1, max_values: int = 1, options: List[SelectOption] = MISSING, - group: Optional[int] = None, + row: Optional[int] = None, ) -> None: self._selected_values: List[str] = [] custom_id = os.urandom(16).hex() if custom_id is MISSING else custom_id @@ -105,7 +111,7 @@ class Select(Item[V]): max_values=max_values, options=options, ) - self.group_id = group + self.row = row @property def custom_id(self) -> str: @@ -229,6 +235,10 @@ class Select(Item[V]): """List[:class:`str`]: A list of values that have been selected by the user.""" return self._selected_values + @property + def width(self) -> int: + return 5 + def to_component_dict(self) -> SelectMenuPayload: return self._underlying.to_dict() @@ -247,7 +257,7 @@ class Select(Item[V]): min_values=component.min_values, max_values=component.max_values, options=component.options, - group=None, + row=None, ) @property @@ -265,7 +275,7 @@ def select( min_values: int = 1, max_values: int = 1, options: List[SelectOption] = MISSING, - group: Optional[int] = None, + row: Optional[int] = None, ) -> Callable[[ItemCallbackType], ItemCallbackType]: """A decorator that attaches a select menu to a component. @@ -281,12 +291,12 @@ def select( 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. - group: Optional[:class:`int`] - The relative group this select menu belongs to. A Discord component can only have 5 - groups. By default, items are arranged automatically into those 5 groups. If you'd - like to control the relative positioning of the group then passing an index is advised. - For example, group=1 will show up before group=2. Defaults to ``None``, which is automatic - ordering. + 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 cannot be negative or greater than 5. 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. @@ -305,7 +315,7 @@ def select( func.__discord_ui_model_kwargs__ = { 'placeholder': placeholder, 'custom_id': custom_id, - 'group': group, + 'row': row, 'min_values': min_values, 'max_values': max_values, 'options': options, |