diff --git a/cogs/logging_cog.py b/cogs/logging_cog.py index ec7c1c8..2d70641 100644 --- a/cogs/logging_cog.py +++ b/cogs/logging_cog.py @@ -77,25 +77,35 @@ class LoggingCog(commands.Cog): self.header.add_item(ui.TextDisplay(description)) self.container.add_item(self.header) - # Section to hold log fields with no accessory. The API requires a - # valid component type, so use a disabled button with an invisible - # label as a placeholder accessory. - self.fields_section = ui.Section( - accessory=ui.Button(label="\u200b", disabled=True) - ) - self.container.add_item(self.fields_section) + # Placeholder for future field sections. They are inserted before + # the separator when the first field is added. + self._field_sections: list[ui.Section] = [] - self.container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small)) + self.separator = ui.Separator(spacing=discord.SeparatorSpacing.small) footer_text = footer or f"Bot ID: {bot.user.id}" + ( f" | User ID: {author.id}" if author else "") self.footer_display = ui.TextDisplay(footer_text) + + self.container.add_item(self.separator) self.container.add_item(self.footer_display) # --- Compatibility helpers --- def add_field(self, name: str, value: str, inline: bool = False): """Mimic Embed.add_field by appending a bolded name/value line.""" - self.fields_section.add_item(ui.TextDisplay(f"**{name}:** {value}")) + if not self._field_sections or len(self._field_sections[-1].children) >= 3: + section = ui.Section(accessory=ui.Button(label="\u200b", disabled=True)) + self._insert_field_section(section) + self._field_sections.append(section) + self._field_sections[-1].add_item(ui.TextDisplay(f"**{name}:** {value}")) + + def _insert_field_section(self, section: ui.Section) -> None: + """Insert a field section before the footer separator.""" + self.container.remove_item(self.separator) + self.container.remove_item(self.footer_display) + self.container.add_item(section) + self.container.add_item(self.separator) + self.container.add_item(self.footer_display) def set_footer(self, text: str): """Mimic Embed.set_footer by replacing the footer text display.""" @@ -295,12 +305,16 @@ class LoggingCog(commands.Cog): await ctx.send(f"✅ Successfully configured logging to send messages to {channel.mention} via the new webhook `{new_webhook.name}`.") # Test send (optional) try: - test_embed = self._create_log_embed( - "✅ Logging Setup Complete", - f"Logs will now be sent to this channel via the webhook `{new_webhook.name}`.", - color=discord.Color.green(), - ) - await new_webhook.send(view=test_embed, username=webhook_name, avatar_url=self.bot.user.display_avatar.url) + test_view = self._create_log_embed( + "✅ Logging Setup Complete", + f"Logs will now be sent to this channel via the webhook `{new_webhook.name}`.", + color=discord.Color.green(), + ) + await new_webhook.send( + view=test_view, + username=webhook_name, + avatar_url=self.bot.user.display_avatar.url, + ) except Exception as e: log.error(f"Failed to send test message via new webhook for guild {guild.id}: {e}") await ctx.send("⚠️ Could not send a test message via the new webhook, but the URL has been saved.")