From dc6d33c30398364bf247c4b22e7afcba2f1bc5cd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E3=83=8A=E3=83=8B=E3=82=AB?= <101696371+ika2kki@users.noreply.github.com> Date: Thu, 18 Apr 2024 17:33:43 +1000 Subject: [PATCH] copy over original row position for dynamic items --- discord/ui/view.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/discord/ui/view.py b/discord/ui/view.py index f3eda6a60..dbe985cd5 100644 --- a/discord/ui/view.py +++ b/discord/ui/view.py @@ -615,16 +615,15 @@ class ViewStore: view = View.from_message(interaction.message, timeout=None) - base_item_index: Optional[int] = None - for index, child in enumerate(view._children): - if child.type.value == component_type and getattr(child, 'custom_id', None) == custom_id: - base_item_index = index - break - - if base_item_index is None: + try: + base_item_index, base_item = next( + (index, child) + for index, child in enumerate(view._children) + if child.type.value == component_type and getattr(child, 'custom_id', None) == custom_id + ) + except StopIteration: return - base_item = view._children[base_item_index] try: item = await factory.from_custom_id(interaction, base_item, match) except Exception: @@ -634,6 +633,7 @@ class ViewStore: # Swap the item in the view with our new dynamic item view._children[base_item_index] = item item._view = view + item._rendered_row = base_item._rendered_row item._refresh_state(interaction, interaction.data) # type: ignore try: