Browse Source

fix: Container.__dispatchable not having new dispatchable nested items added after a dispatchable item was added in add_item

pull/10166/head
DA-344 2 weeks ago
parent
commit
eb38195e80
  1. 3
      discord/ui/action_row.py
  2. 20
      discord/ui/container.py

3
discord/ui/action_row.py

@ -277,6 +277,9 @@ class ActionRow(Item[V]):
if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
self._view._total_children += 1
if item.is_dispatchable() and self._parent and getattr(self._parent, '__discord_ui_container__', False):
self._parent._add_dispatchable(item) # type: ignore
return self
def remove_item(self, item: Item[Any]) -> Self:

20
discord/ui/container.py

@ -160,6 +160,15 @@ class Container(Item[V]):
self.row = row
self.id = id
def _add_dispatchable(self, item: Item[Any]) -> None:
self.__dispatchable.append(item)
def _remove_dispatchable(self, item: Item[Any]) -> None:
try:
self.__dispatchable.remove(item)
except ValueError:
pass
def _init_children(self) -> List[Item[Any]]:
children = []
parents = {}
@ -393,20 +402,15 @@ class Container(Item[V]):
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
self._remove_dispatchable(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)
self._remove_dispatchable(c)
else:
self.__dispatchable.remove(item)
except ValueError:
pass
self._remove_dispatchable(item)
if self._view and getattr(self._view, '__discord_ui_layout_view__', False):
if getattr(item, '__discord_ui_update_view__', False):

Loading…
Cancel
Save