aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Gareth Coles <[email protected]>2018-02-05 20:52:56 +0000
committerGravatar Gareth Coles <[email protected]>2018-02-05 20:52:56 +0000
commit65b1b4492944e813e784cc9e72f3a825c4cb3efb (patch)
tree86f3cb6a886823c72187769fc4b81c2eba6c49ad
parentFix prefixes (diff)
Events cog; currently handles command errors
-rw-r--r--bot/__main__.py1
-rw-r--r--bot/cogs/events.py50
2 files changed, 51 insertions, 0 deletions
diff --git a/bot/__main__.py b/bot/__main__.py
index b0cdbe803..32686a27a 100644
--- a/bot/__main__.py
+++ b/bot/__main__.py
@@ -8,6 +8,7 @@ bot = AutoShardedBot(command_prefix=when_mentioned_or(">>> ", ">>>"))
# Internal/debug
bot.load_extension("bot.cogs.logging")
bot.load_extension("bot.cogs.security")
+bot.load_extension("bot.cogs.events")
# Owner-only
bot.load_extension("bot.cogs.eval")
diff --git a/bot/cogs/events.py b/bot/cogs/events.py
new file mode 100644
index 000000000..35f09d913
--- /dev/null
+++ b/bot/cogs/events.py
@@ -0,0 +1,50 @@
+# coding=utf-8
+from discord import Guild
+from discord.ext.commands import (
+ AutoShardedBot, CommandError, Context, BadArgument, NoPrivateMessage,
+ CommandInvokeError, UserInputError, BotMissingPermissions
+)
+
+__author__ = "Gareth Coles"
+
+
+class Events:
+ """
+ No commands, just event handlers
+ """
+
+ def __init__(self, bot: AutoShardedBot):
+ self.bot = bot
+
+ async def on_command_error(self, ctx: Context, e: CommandError):
+ command = ctx.command
+ parent = command.parent
+
+ if parent:
+ help_command = (self.bot.get_command("help"), parent.name, command.name)
+ else:
+ help_command = (self.bot.get_command("help"), command.name)
+
+ if isinstance(e, BadArgument):
+ await ctx.send(f"Bad argument: {e}\n")
+ await ctx.invoke(*help_command)
+ elif isinstance(e, UserInputError):
+ await ctx.invoke(*help_command)
+ elif isinstance(e, NoPrivateMessage):
+ await ctx.send("Sorry, this command can't be used in a private message!")
+ elif isinstance(e, BotMissingPermissions):
+ await ctx.send(
+ f"Sorry, it looks like I don't have the permissions I need to do that.\n\n"
+ f"Here's what I'm missing: **{e.missing_perms}**"
+ )
+ elif isinstance(e, CommandInvokeError):
+ await ctx.send(
+ f"Sorry, an unexpected error occurred. Please let us know!\n\n```{e}```"
+ )
+ raise e.original
+ print(e)
+
+
+def setup(bot):
+ bot.add_cog(Events(bot))
+ print("Cog loaded: Events")