Skip to content
Discussion options

You must be logged in to vote

You can make a separate cog for handling the exceptions inside your Discord bot.

on_command_error is already dispatched for hybrid commands as well.

# cogs/exception-handler.py

import discord
from discord.ext import commands

class ExceptionHandler(commands.Cog):
    def __init__(self, bot: commands.Bot) -> None:
        self.bot = bot

    @commands.Cog.listener()
    async def on_command_error(self, ctx: commands.Context, error) -> None:
        pass # do your things here
        
async def setup(bot: commands.Bot) -> None:
    await bot.add_cog(ExceptionHandler(bot))

Replies: 3 comments 5 replies

Comment options

You must be logged in to vote
4 replies
@hirusha-adi
Comment options

@Rapptz
Comment options

@hirusha-adi
Comment options

@PaulMarisOUMary
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by keqking
Comment options

You must be logged in to vote
1 reply
@hitblast
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
5 participants