Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions capy_discord/bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
from discord.ext import commands

from capy_discord.errors import UserFriendlyError
from capy_discord.exts.core.telemetry import Telemetry
from capy_discord.ui.embeds import error_embed
from capy_discord.utils import EXTENSIONS

Expand Down Expand Up @@ -32,6 +33,11 @@ async def on_tree_error(self, interaction: discord.Interaction, error: app_comma
if isinstance(error, app_commands.CommandInvokeError):
actual_error = error.original

# Track all failures in telemetry (both user-friendly and unexpected)
telemetry = self.get_cog("Telemetry")
if isinstance(telemetry, Telemetry):
telemetry.log_command_failure(interaction, error)

if isinstance(actual_error, UserFriendlyError):
embed = error_embed(description=actual_error.user_message)
if interaction.response.is_done():
Expand All @@ -51,7 +57,6 @@ async def on_tree_error(self, interaction: discord.Interaction, error: app_comma

async def on_command_error(self, ctx: commands.Context, error: commands.CommandError) -> None:
"""Handle errors in prefix commands."""
# Unpack CommandInvokeError
actual_error = error
if isinstance(error, commands.CommandInvokeError):
actual_error = error.original
Expand All @@ -63,7 +68,7 @@ async def on_command_error(self, ctx: commands.Context, error: commands.CommandE

# Generic error handling
logger = self._get_logger_for_command(ctx.command)
logger.exception("Command error: %s", error)
logger.exception("Prefix command error: %s", error)
embed = error_embed(description="An unexpected error occurred. Please try again later.")
await ctx.send(embed=embed)

Expand Down
1 change: 1 addition & 0 deletions capy_discord/exts/core/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Core bot functionality including telemetry and system monitoring."""
Loading