permission(s) to run this command.'.format(fmt)
await ctx.send(_message)
return
if isinstance(error, commands.DisabledCommand):
await ctx.send('This command has been disabled.')
return
if isinstance(error, commands.CommandOnCooldown):
await ctx.send(f'This command is actually on cooldown, you can use it in {round(error.retry_after, 2)} seconds.')
return
if isinstance(error, commands.MissingPermissions):
missing = [perm.replace('_', ' ').replace('guild', 'server').title() for perm in error.missing_perms]
if len(missing) > 2:
fmt = '{}, and {}'.format("**, **".join(missing[:-1]), missing[-1])
else:
fmt = ' and '.join(missing)
_message = 'You need the **{}** permission(s) to use this command.'.format(fmt)
await ctx.send(_message)
return
if isinstance(error, commands.UserInputError):
return await ctx.send("Invalid input.")
if isinstance(error, commands.NoPrivateMessage):
try:
await ctx.author.send('This command cannot be used in direct messages.')
except discord.Forbidden:
pass
return
if isinstance(error, commands.CheckFailure):
await ctx.send("You do not have permission to use this command.")
return
# ignore all other exception types, but print them to stderr
print('Ignoring exception in command {}:'.format(ctx.command), file=sys.stderr)
traceback.print_exception(type(error), error, error.__traceback__, file=sys.stderr)
async def setup(bot):
await bot.add_cog(CommandErrorHandler(bot))