From ae372779aa53f39c40c59103ce0a096ffd179869 Mon Sep 17 00:00:00 2001 From: sgtlaggy <8661717+sgtlaggy@users.noreply.github.com> Date: Sat, 14 Jan 2023 11:29:28 -0800 Subject: [PATCH] Add extra error handling to converters example --- examples/converters.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/examples/converters.py b/examples/converters.py index bc82a6a4d..ad275f539 100644 --- a/examples/converters.py +++ b/examples/converters.py @@ -1,3 +1,4 @@ +import traceback import typing import discord @@ -29,10 +30,15 @@ async def userinfo(ctx: commands.Context, user: discord.User): @userinfo.error async def userinfo_error(ctx: commands.Context, error: commands.CommandError): - # if the conversion above fails for any reason, it will raise `commands.BadArgument` + # If the conversion above fails for any reason, it will raise `commands.BadArgument` # so we handle this in this error handler: if isinstance(error, commands.BadArgument): return await ctx.send('Couldn\'t find that user.') + # The default `on_command_error` will ignore errors from this command + # because we made our own command-specific error handler, + # so we need to log tracebacks ourselves. + else: + traceback.print_exception(type(error), error, error.__traceback__) # Custom Converter here