Fix logging view field insertion

This commit is contained in:
Codex 2025-06-06 16:11:38 +00:00 committed by Slipstream
parent d0ca79d059
commit e22847d5d6
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD

View File

@ -152,9 +152,18 @@ class LoggingCog(commands.Cog):
def add_field(self, name: str, value: str, inline: bool = False) -> None:
field = ui.TextDisplay(f"**{name}:** {value}")
if hasattr(self.container, "children"):
index = self.container.children.index(self.bottom_separator)
self.container.children.insert(index, field)
# Ensure the field is properly registered with the view by using
# add_item first, then repositioning it before the bottom separator
if hasattr(self.container, "_children"):
self.container.add_item(field)
try:
children = self.container._children
index = children.index(self.bottom_separator)
children.remove(field)
children.insert(index, field)
except ValueError:
# Fallback to default behaviour if the separator is missing
pass
else:
self.content_container.add_item(field)