#!/bin/env python

import sys
import traceback
from discord.ext import commands


class ErrorHandler:
    def __init__(self, bot):
        self.bot = bot

    async def on_command_error(self, ctx, error):
        """ Handle command errors more gracefully """

        if isinstance(error, commands.CommandNotFound):
            return

        if isinstance(error, commands.NotOwner):
            return await ctx.send('Sorry, only the owner of qtbot may run this command.')

        if isinstance(error, commands.CommandOnCooldown):
            return await ctx.send(f'This command is on cooldown. Please retry in `{error.retry_after:.0f}` second(s).')

        if isinstance(error, commands.MissingRequiredArgument):
            return await ctx.send(f'Command missing required argument `{error.param}`.')

        if isinstance(error, commands.BadArgument):
            return await ctx.send(f'Bad argument(s): `{", ".join(ctx.kwargs.values())}`.')

        if isinstance(error, commands.MissingPermissions):
            return await ctx.send(f'Sorry you need permissions: `{",".join(error.missing_perms)}` to do that.')

        if isinstance(error, commands.BotMissingPermissions):
            return await ctx.send(f'Sorry I need permissions: `{",".join(error.missing_perms)}` to do that.')

        print(f'Ignoring exception in command {ctx.command}:', file=sys.stderr)
        traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)


def setup(bot):
    bot.add_cog(ErrorHandler(bot))

@@ -806,152 +806,8 @@
 ')%0A%0A
-        if isinstance(error, commands.BadArgument):%0A            return await ctx.send(f'Bad argument(s): %60%7B%22, %22.join(ctx.kwargs.values())%7D%60.')%0A%0A
     

move BadArgument to cog