From 22e473891824c8ea8f92e5a000ed7c651af5a20a Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Sun, 20 Apr 2025 14:12:16 +0200 Subject: [PATCH] chore: Fix interaction_check not being called correctly --- discord/ui/action_row.py | 1 + discord/ui/container.py | 6 ++++++ discord/ui/item.py | 8 +++----- discord/ui/section.py | 1 + 4 files changed, 11 insertions(+), 5 deletions(-) diff --git a/discord/ui/action_row.py b/discord/ui/action_row.py index b3c9837ad..b2d713f5a 100644 --- a/discord/ui/action_row.py +++ b/discord/ui/action_row.py @@ -198,6 +198,7 @@ class ActionRow(Item[V]): raise TypeError(f'expected Item not {item.__class__.__name__}') item._view = self._view + item._parent = self self._children.append(item) return self diff --git a/discord/ui/container.py b/discord/ui/container.py index 260577de9..84147d882 100644 --- a/discord/ui/container.py +++ b/discord/ui/container.py @@ -275,10 +275,16 @@ class Container(Item[V]): if item.is_dispatchable(): if getattr(item, '__discord_ui_section__', False): self.__dispatchable.append(item.accessory) # type: ignore + elif hasattr(item, '_children'): + self.__dispatchable.extend([i for i in item._children if i.is_dispatchable()]) # type: ignore + else: + self.__dispatchable.append(item) if getattr(item, '__discord_ui_update_view__', False): item._update_children_view(self.view) # type: ignore + item._view = self.view + item._parent = self return self def remove_item(self, item: Item[Any]) -> Self: diff --git a/discord/ui/item.py b/discord/ui/item.py index 4206274c3..47a31633b 100644 --- a/discord/ui/item.py +++ b/discord/ui/item.py @@ -81,6 +81,7 @@ class Item(Generic[V]): self._provided_custom_id: bool = False self._id: Optional[int] = None self._max_row: int = 5 if not self._is_v2() else 10 + self._parent: Optional[Item] = None if self._is_v2(): # this is done so v2 components can be stored on ViewStore._views @@ -154,11 +155,8 @@ class Item(Generic[V]): async def _run_checks(self, interaction: Interaction[ClientT]) -> bool: can_run = await self.interaction_check(interaction) - if can_run: - parent = getattr(self, '_parent', None) - - if parent is not None: - can_run = await parent._run_checks(interaction) + if can_run and self._parent: + can_run = await self._parent._run_checks(interaction) return can_run diff --git a/discord/ui/section.py b/discord/ui/section.py index 98784d50a..53d433c3e 100644 --- a/discord/ui/section.py +++ b/discord/ui/section.py @@ -141,6 +141,7 @@ class Section(Item[V]): item = item if isinstance(item, Item) else TextDisplay(item) item._view = self.view + item._parent = self self._children.append(item) return self