Example #1
0
    async def cog_command_error(self, ctx: Context,
                                error: commands.CommandError) -> None:
        """Handles errors for commands within this cog."""
        if isinstance(error, commands.BadUnionArgument):
            if discord.User in error.converters:
                await ctx.send(str(error.errors[0]))
                error.handled = True

        elif isinstance(error, InvalidInfraction):
            if error.infraction_arg.isdigit():
                await ctx.send(
                    f":x: Could not find an infraction with id `{error.infraction_arg}`."
                )
            else:
                await ctx.send(
                    f":x: `{error.infraction_arg}` is not a valid integer infraction id."
                )
            error.handled = True
Example #2
0
 async def command_error(self, ctx: Context, error: CommandError) -> None:
     """Local error handler for the Snake Cog."""
     original_error = getattr(error, "original", None)
     if isinstance(original_error, OSError):
         error.handled = True
         embed = Embed()
         embed.colour = Colour.red()
         log.error(f"snake_card encountered an OSError: {error} ({original_error})")
         embed.description = "Could not generate the snake card! Please try again."
         embed.title = random.choice(ERROR_REPLIES)
         await ctx.send(embed=embed)
Example #3
0
 async def handle_madlibs_error(self, ctx: commands.Context,
                                error: commands.CommandError) -> None:
     """Error handler for the Madlibs command."""
     if isinstance(error, commands.MaxConcurrencyReached):
         await ctx.send("You are already playing Madlibs!")
         error.handled = True