From 097201e5c92af1b489f4f8c619262e397d1a784b Mon Sep 17 00:00:00 2001 From: EvieePy Date: Wed, 23 Aug 2023 15:05:00 +1000 Subject: [PATCH] Fix to command error handler of BadArgument and MissingRequiredArgument --- twitchio/ext/commands/core.py | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/twitchio/ext/commands/core.py b/twitchio/ext/commands/core.py index 57556545..4e4c519c 100644 --- a/twitchio/ext/commands/core.py +++ b/twitchio/ext/commands/core.py @@ -201,8 +201,6 @@ async def invoke(self, context: Context, *, index=0) -> None: # TODO Docs if not context.view: return - args, kwargs = await self.parse_args(context, self._instance, context.view.words, index=index) - context.args, context.kwargs = args, kwargs async def try_run(func, *, to_command=False): try: @@ -213,6 +211,17 @@ async def try_run(func, *, to_command=False): else: context.bot.run_event("command_error", context, _e) + try: + args, kwargs = await self.parse_args(context, self._instance, context.view.words, index=index) + except (MissingRequiredArgument, BadArgument) as e: + if self.event_error: + args_ = [self._instance, context] if self._instance else [context] + await try_run(self.event_error(*args_, e)) + + context.bot.run_event("command_error", context, e) + return + + context.args, context.kwargs = args, kwargs check_result = await self.handle_checks(context) if check_result is not True: