diff --git a/cogs/logging_cog.py b/cogs/logging_cog.py index 54cf6b9..a5081ce 100644 --- a/cogs/logging_cog.py +++ b/cogs/logging_cog.py @@ -77,12 +77,15 @@ 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. + # Section to hold log fields with no accessory. The API requires at + # least one child component, so include an empty text display that + # will be removed when actual fields are added. A disabled button is + # used as the accessory to satisfy Discord's component validation. self.fields_section = ui.Section( accessory=ui.Button(label="\u200b", disabled=True) ) + self._fields_placeholder = ui.TextDisplay("\u200b") + self.fields_section.add_item(self._fields_placeholder) self.container.add_item(self.fields_section) self.container.add_item(ui.Separator(spacing=discord.SeparatorSpacing.small)) @@ -95,6 +98,11 @@ class LoggingCog(commands.Cog): # --- Compatibility helpers --- def add_field(self, name: str, value: str, inline: bool = False): """Mimic Embed.add_field by appending a bolded name/value line.""" + if ( + hasattr(self, "_fields_placeholder") + and self._fields_placeholder in self.fields_section.children + ): + self.fields_section.remove_item(self._fields_placeholder) self.fields_section.add_item(ui.TextDisplay(f"**{name}:** {value}")) def set_footer(self, text: str): @@ -295,12 +303,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.")