Skip to content

Commit

Permalink
Fix to command error handler of BadArgument and MissingRequiredArgument
Browse files Browse the repository at this point in the history
  • Loading branch information
EvieePy committed Aug 23, 2023
1 parent 4b9cc85 commit 097201e
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions twitchio/ext/commands/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down

0 comments on commit 097201e

Please sign in to comment.