From a19055b308a4ef58401c44c23f390077ce064ed0 Mon Sep 17 00:00:00 2001 From: DA-344 <108473820+DA-344@users.noreply.github.com> Date: Thu, 15 May 2025 15:35:54 +0200 Subject: [PATCH] __dispatchable having children that were removed from the Container --- discord/ui/container.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/discord/ui/container.py b/discord/ui/container.py index e9c7494d8..199835179 100644 --- a/discord/ui/container.py +++ b/discord/ui/container.py @@ -356,7 +356,7 @@ 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'): + elif getattr(item, '__discord_ui_action_row__', False): self.__dispatchable.extend([i for i in item._children if i.is_dispatchable()]) # type: ignore else: self.__dispatchable.append(item) @@ -392,6 +392,22 @@ class Container(Item[V]): except ValueError: pass else: + if item.is_dispatchable(): + # none of this should error, but wrap in a try/except block + # anyways. + try: + if getattr(item, '__discord_ui_section__', False): + self.__dispatchable.remove(item.accessory) # type: ignore + elif getattr(item, '__discord_ui_action_row__', False): + for c in item._children: # type: ignore + if not c.is_dispatchable(): + continue + self.__dispatchable.remove(c) + else: + self.__dispatchable.remove(item) + except ValueError: + pass + if self._view and getattr(self._view, '__discord_ui_layout_view__', False): if getattr(item, '__discord_ui_update_view__', False): self._view._total_children -= len(tuple(item.walk_children())) # type: ignore @@ -429,4 +445,5 @@ class Container(Item[V]): if self._view and getattr(self._view, '__discord_ui_layout_view__', False): self._view._total_children -= sum(1 for _ in self.walk_children()) self._children.clear() + self.__dispatchable.clear() return self