-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patherrorhandling.py
More file actions
58 lines (53 loc) · 2.99 KB
/
errorhandling.py
File metadata and controls
58 lines (53 loc) · 2.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#errorhandling.py: handles most errors. old and needs to be updated
import aiomysql
import discord
from discord.ext import commands
class errorhandling(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
owner = self.bot.get_user(self.bot.config['owner_id'])
try:
await owner.send(f"An error occurred in {ctx.guild.name} ({ctx.guild.id}): ")
await self.bot.core.send_traceback(owner, error)
except:
pass
#get the original error so isinstance works
error = getattr(error, "original", error)
cog = ctx.cog
if cog:
#ignore errors handled in cog_command_error
if cog._get_overridden_method(cog.cog_command_error) is not None:
return
#check for database errors first, these should almost never happen
if isinstance(error, aiomysql.OperationalError) or isinstance(error, aiomysql.ProgrammingError):
embed = self.bot.core.ThemedEmbed(title=self.bot.strings["GENERIC_FATAL_ERROR_TITLE"],description=self.bot.strings["GENERIC_FATAL_ERROR"])
if ctx.guild.me.guild_permissions.embed_links:
await ctx.send(embed=embed)
elif isinstance(error, commands.BotMissingPermissions) or isinstance(error, discord.errors.Forbidden) or 'discord.errors.Forbidden' in str(error):
try:
embed = self.bot.core.ThemedEmbed(title=self.bot.strings["ERROR_MISSING_PERMISSIONS_SPECIFIC"].format(error.missing_perms[0]))
except AttributeError:
embed = self.bot.core.ThemedEmbed(title=self.bot.strings["ERROR_MISSING_PERMISSIONS_GENERAL"])
if ctx.guild.me.guild_permissions.embed_links:
await ctx.send(embed=embed)
elif isinstance(error, commands.MissingPermissions) or isinstance(error, commands.NotOwner):
message = self.bot.strings["ERROR_USER_MISSING_PERMISSIONS"].format(await self.bot.get_prefix(ctx.message))
await ctx.send(message)
elif isinstance(error, commands.DisabledCommand):
return await ctx.send(embed=self.bot.core.ThemedEmbed(title=self.bot.strings["ERROR_COMMAND_DISABLED"]))
elif isinstance(error, commands.MissingRequiredArgument):
if ctx.guild.me.guild_permissions.embed_links:
embed = self.bot.core.ThemedEmbed(title=self.bot.strings["ERROR_MISSING_ARGUMENT"].format(error.param.name, ctx.command.name))
await ctx.send(embed=embed)
elif isinstance(error, commands.CommandNotFound):
return
else:
await ctx.send(embed=self.bot.core.ThemedEmbed(title=self.bot.strings["GENERIC_ERROR_TITLE"], description=self.bot.strings["GENERIC_ERROR"]))
if not str(error):
error = error.__name__
await ctx.send(f"`{error}`")
await self.bot.core.send_debug(ctx)
async def setup(bot):
await bot.add_cog(errorhandling(bot))