Browse Source

__dispatchable having children that were removed from the Container

pull/10166/head
DA-344 2 weeks ago
parent
commit
a19055b308
  1. 19
      discord/ui/container.py

19
discord/ui/container.py

@ -356,7 +356,7 @@ class Container(Item[V]):
if item.is_dispatchable(): if item.is_dispatchable():
if getattr(item, '__discord_ui_section__', False): if getattr(item, '__discord_ui_section__', False):
self.__dispatchable.append(item.accessory) # type: ignore 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 self.__dispatchable.extend([i for i in item._children if i.is_dispatchable()]) # type: ignore
else: else:
self.__dispatchable.append(item) self.__dispatchable.append(item)
@ -392,6 +392,22 @@ class Container(Item[V]):
except ValueError: except ValueError:
pass pass
else: 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 self._view and getattr(self._view, '__discord_ui_layout_view__', False):
if getattr(item, '__discord_ui_update_view__', False): if getattr(item, '__discord_ui_update_view__', False):
self._view._total_children -= len(tuple(item.walk_children())) # type: ignore 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): if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
self._view._total_children -= sum(1 for _ in self.walk_children()) self._view._total_children -= sum(1 for _ in self.walk_children())
self._children.clear() self._children.clear()
self.__dispatchable.clear()
return self return self

Loading…
Cancel
Save