From 5489806a624e5a536446455a08844111e1be9fb1 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Tue, 20 May 2025 20:36:22 +0200 Subject: [PATCH] fix: row not being respected when being 0 --- discord/ui/action_row.py | 8 +++++++- discord/ui/container.py | 8 +++++++- discord/ui/section.py | 10 +++++++++- discord/ui/view.py | 9 ++++++++- 4 files changed, 31 insertions(+), 4 deletions(-) diff --git a/discord/ui/action_row.py b/discord/ui/action_row.py index 167d1664f..4f27de4f1 100644 --- a/discord/ui/action_row.py +++ b/discord/ui/action_row.py @@ -338,7 +338,13 @@ class ActionRow(Item[V]): def to_component_dict(self) -> Dict[str, Any]: components = [] - key = lambda i: i._rendered_row or i._row or sys.maxsize + def key(item: Item) -> int: + if item._rendered_row is not None: + return item._rendered_row + if item._row is not None: + return item._row + return sys.maxsize + for _, cmps in groupby(self._children, key=key): components.extend(c.to_component_dict() for c in cmps) diff --git a/discord/ui/container.py b/discord/ui/container.py index 1837e3d71..c74104237 100644 --- a/discord/ui/container.py +++ b/discord/ui/container.py @@ -268,7 +268,13 @@ class Container(Item[V]): def to_components(self) -> List[Dict[str, Any]]: components = [] - key = lambda i: (i._rendered_row or i._row or sys.maxsize) + 1 + def key(item: Item) -> int: + if item._rendered_row is not None: + return item._rendered_row + if item._row is not None: + return item._row + return sys.maxsize + for i in sorted(self._children, key=key): components.append(i.to_component_dict()) return components diff --git a/discord/ui/section.py b/discord/ui/section.py index dd04431e6..fcd2002e9 100644 --- a/discord/ui/section.py +++ b/discord/ui/section.py @@ -239,7 +239,15 @@ class Section(Item[V]): def to_components(self) -> List[Dict[str, Any]]: components = [] - for _, comps in groupby(self._children, key=lambda i: i._rendered_row or i._row or sys.maxsize): + + def key(item: Item) -> int: + if item._rendered_row is not None: + return item._rendered_row + if item._row is not None: + return item._row + return sys.maxsize + + for _, comps in groupby(self._children, key=key): components.extend(c.to_component_dict() for c in comps) return components diff --git a/discord/ui/view.py b/discord/ui/view.py index cd9c81958..e877457d7 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -983,7 +983,14 @@ class LayoutView(BaseView): # sorted by row, which in LayoutView indicates the position of the component in the # payload instead of in which ActionRow it should be placed on. - key = lambda i: (i._rendered_row or i._row or sys.maxsize) + 1 + + def key(item: Item) -> int: + if item._rendered_row is not None: + return item._rendered_row + if item._row is not None: + return item._row + return sys.maxsize + for i in sorted(self._children, key=key): components.append(i.to_component_dict())