aboutsummaryrefslogtreecommitdiff
path: root/discord/ui/button.py
diff options
context:
space:
mode:
authorRapptz <[email protected]>2021-05-29 23:58:37 -0400
committerRapptz <[email protected]>2021-05-29 23:58:37 -0400
commit7bd1211b36dc256e064b5030b56007c1eee2b5df (patch)
treecf206c7b952d1c31747ceb209e2791a4ceb8f415 /discord/ui/button.py
parentFix Messageable.send overload to take view parameters (diff)
downloaddiscord.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/button.py')
-rw-r--r--discord/ui/button.py30
1 files changed, 18 insertions, 12 deletions
diff --git a/discord/ui/button.py b/discord/ui/button.py
index 220d55de..777d31ce 100644
--- a/discord/ui/button.py
+++ b/discord/ui/button.py
@@ -66,6 +66,12 @@ class Button(Item[V]):
The label of the button, if any.
emoji: Optional[:class:`PartialEmoji`]
The emoji of the button, if available.
+ row: Optional[:class:`int`]
+ The relative row this button 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, ...] = (
@@ -74,7 +80,7 @@ class Button(Item[V]):
'disabled',
'label',
'emoji',
- 'group_id',
+ 'row',
)
def __init__(
@@ -86,7 +92,7 @@ class Button(Item[V]):
custom_id: Optional[str] = None,
url: Optional[str] = None,
emoji: Optional[Union[str, PartialEmoji]] = None,
- group: Optional[int] = None,
+ row: Optional[int] = None,
):
super().__init__()
if custom_id is not None and url is not None:
@@ -110,7 +116,7 @@ class Button(Item[V]):
style=style,
emoji=emoji,
)
- self.group_id = group
+ self.row = row
@property
def style(self) -> ButtonStyle:
@@ -189,7 +195,7 @@ class Button(Item[V]):
custom_id=button.custom_id,
url=button.url,
emoji=button.emoji,
- group=None,
+ row=None,
)
@property
@@ -213,7 +219,7 @@ def button(
disabled: bool = False,
style: ButtonStyle = ButtonStyle.secondary,
emoji: Optional[Union[str, PartialEmoji]] = None,
- group: Optional[int] = None,
+ row: Optional[int] = None,
) -> Callable[[ItemCallbackType], ItemCallbackType]:
"""A decorator that attaches a button to a component.
@@ -242,12 +248,12 @@ def button(
Whether the button is disabled or not. Defaults to ``False``.
emoji: Optional[Union[:class:`str`, :class:`PartialEmoji`]]
The emoji of the button. This can be in string form or a :class:`PartialEmoji`.
- group: Optional[:class:`int`]
- The relative group this button 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 button 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.
"""
def decorator(func: ItemCallbackType) -> ItemCallbackType:
@@ -264,7 +270,7 @@ def button(
'disabled': disabled,
'label': label,
'emoji': emoji,
- 'group': group,
+ 'row': row,
}
return func