refactor(welcome-cog): Use cog-wide error handler

Migrates individual command error handlers to the cog-wide `cog_command_error` method. This simplifies error handling by automatically catching errors from all commands within the cog.
Adds `ephemeral=True` to error messages sent to the user and logs the `original_error` for better debugging.
This commit is contained in:
Slipstreamm 2025-06-14 13:35:30 -06:00
parent 4c17db72a8
commit db5c171c11

View File

@ -435,29 +435,28 @@ class WelcomeCog(commands.Cog):
await ctx.send("An unexpected error occurred.", ephemeral=True) await ctx.send("An unexpected error occurred.", ephemeral=True)
# Error Handling for this Cog # Error Handling for this Cog
@set_welcome.error async def cog_command_error(self, ctx: commands.Context, error: commands.CommandError):
@disable_welcome.error """Handles errors for all commands in this cog."""
@set_goodbye.error
@disable_goodbye.error
@testmessage.error
async def on_command_error(self, ctx: commands.Context, error):
if isinstance(error, commands.MissingPermissions): if isinstance(error, commands.MissingPermissions):
await ctx.send("You need Administrator permissions to use this command.") await ctx.send("You need Administrator permissions to use this command.", ephemeral=True)
elif isinstance(error, commands.BadArgument): elif isinstance(error, commands.BadArgument):
await ctx.send( await ctx.send(
f"Invalid argument provided. Check the command help: `{ctx.prefix}help {ctx.command.name}`" f"Invalid argument provided. Check the command help: `{ctx.prefix}help {ctx.command.name}`",
ephemeral=True
) )
elif isinstance(error, commands.MissingRequiredArgument): elif isinstance(error, commands.MissingRequiredArgument):
await ctx.send( await ctx.send(
f"Missing required argument. Check the command help: `{ctx.prefix}help {ctx.command.name}`" f"Missing required argument. Check the command help: `{ctx.prefix}help {ctx.command.name}`",
ephemeral=True
) )
elif isinstance(error, commands.NoPrivateMessage): elif isinstance(error, commands.NoPrivateMessage):
await ctx.send("This command cannot be used in private messages.") await ctx.send("This command cannot be used in private messages.", ephemeral=True)
else: else:
original_error = getattr(error, 'original', error)
log.error( log.error(
f"Unhandled error in WelcomeCog command '{ctx.command.name}': {error}" f"Unhandled error in WelcomeCog command '{ctx.command.name}': {original_error}"
) )
await ctx.send("An unexpected error occurred. Please check the logs.") await ctx.send("An unexpected error occurred. Please check the logs.", ephemeral=True)
async def setup(bot: commands.Bot): async def setup(bot: commands.Bot):