From 5c13dab8e57c2f27c4a7eb9c9c897386b05b9ec1 Mon Sep 17 00:00:00 2001 From: Twentysix Date: Sun, 18 Sep 2016 23:53:15 +0200 Subject: [PATCH] [Main] Handle NoPrivateMessage errors --- red.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/red.py b/red.py index ff5eaac2f..e8065c95f 100644 --- a/red.py +++ b/red.py @@ -76,24 +76,27 @@ async def on_message(message): @bot.event async def on_command_error(error, ctx): + channel = ctx.message.channel if isinstance(error, commands.MissingRequiredArgument): await send_cmd_help(ctx) elif isinstance(error, commands.BadArgument): await send_cmd_help(ctx) elif isinstance(error, commands.DisabledCommand): - await bot.send_message(ctx.message.channel, - "That command is disabled.") + await bot.send_message(channel, "That command is disabled.") elif isinstance(error, commands.CommandInvokeError): logger.exception("Exception in command '{}'".format( ctx.command.qualified_name), exc_info=error.original) oneliner = "Error in command '{}' - {}: {}".format( ctx.command.qualified_name, type(error.original).__name__, str(error.original)) - await ctx.bot.send_message(ctx.message.channel, inline(oneliner)) + await ctx.bot.send_message(channel, inline(oneliner)) elif isinstance(error, commands.CommandNotFound): pass elif isinstance(error, commands.CheckFailure): pass + elif isinstance(error, commands.NoPrivateMessage): + await bot.send_message(channel, "That command is not " + "available in DMs.") else: logger.exception(type(error).__name__, exc_info=error)