pycord icon indicating copy to clipboard operation
pycord copied to clipboard

Raising errors inside checks or commands don't call error events

Open middledot opened this issue 5 years ago • 5 comments

Summary

Making checks raise their own errors so that it doesn't just raise the generic .CheckFailure seems to be giving fatal errors and stopping the bot from running anymore on VSCode.

Reproduction Steps

  1. Make a custom check that raises an error from discord.errors or subclassed from one of them
  2. observe

Minimal Reproducible Code

def require_js():
    async def predicate(ctx):
        config = await ctx.bot.cogs["JoinLeave"].get_config(ctx.guild.id)
        if config == None:
            raise commands.BadArgument('Welcome messages are disabled.')
        else:
            if config.join.toggle == False:
                raise commands.BadArgument('Welcome messages are disabled.')
            ctx.config = config
            return True
    return commands.check(predicate)

used in the command: (in a cog)

    @joinsettings.group(name="message", invoke_without_command=True)
    @require_js()
    async def js_message(self, ctx, *, message:typing.Optional[str]):
        ...

error handler: (in bot subclass)

    async def on_command_error(self, ctx, error):
        if ...:
            ...
        elif isinstance(error, commands.BadArgument):
            if ...:
                ...
            else:
                try:
                    await ctx.send(f'❔ {str(error).split(":")[0]}')
                except IndexError:
                    await ctx.send(f'❔ {str(error)}')

Expected Results

Bot says Welcome messages are disabled

Actual Results

Bot stops running

image

Intents

None

System Information

  • Python v3.9.0-final
  • py-cord v2.0.0-alpha
    • py-cord pkg_resources: v2.0.0a4148+g2bbf063
  • aiohttp v3.6.2
  • system info: Windows 10 10.0.19041

Checklist

  • [X] I have searched the open issues for duplicates.
  • [X] I have shown the entire traceback, if possible.
  • [X] I have removed my token from display, if visible.

Additional Context

No response

middledot avatar Oct 10 '21 17:10 middledot

I cannot reproduce this error with the code provided

ToxicKidz avatar Oct 17 '21 19:10 ToxicKidz

I cannot reproduce this error with the code provided

Are you using VSCode and the error is going to the event?

middledot avatar Oct 18 '21 13:10 middledot

I've updated the issue description with a matching image and more code

middledot avatar Oct 19 '21 21:10 middledot

Also errors aren't working inside the command:

image

middledot avatar Oct 24 '21 14:10 middledot

Somehow works now

middledot avatar Oct 31 '21 17:10 middledot