You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
3.4KB

  1. import traceback
  2. import datetime
  3. import discord
  4. from discord.ext import commands
  5. from config.server_config import ServerConfig
  6. class ErrHandle:
  7. def __init__(self, bot_client):
  8. self.bot = bot_client
  9. self.dev = False # For debugging
  10. self.servers = ServerConfig().servers
  11. async def on_error(self, event, *args, **kwargs):
  12. if self.dev:
  13. traceback.print_exc()
  14. else:
  15. embed = discord.Embed(title="Roxbot Error", colour=0xe74c3c) # Red
  16. embed.add_field(name='Event', value=event)
  17. embed.description = '```py\n{}\n```'.format(traceback.format_exc())
  18. embed.timestamp = datetime.datetime.utcnow()
  19. await self.owner.send(embed=embed)
  20. async def on_command_error(self, ctx, error):
  21. self.owner = self.bot.get_user(self.bot.owner_id)
  22. err_colour = 0x992d22
  23. if self.dev:
  24. raise error
  25. elif isinstance(error, commands.CommandInvokeError):
  26. embed = discord.Embed(title='Command Error', colour=err_colour)
  27. embed.description = str(error)
  28. embed.add_field(name='Server', value=ctx.guild)
  29. embed.add_field(name='Channel', value=ctx.channel.mention)
  30. embed.add_field(name='User', value=ctx.author)
  31. embed.add_field(name='Message', value=ctx.message.content)
  32. embed.timestamp = datetime.datetime.utcnow()
  33. await self.owner.send(embed=embed)
  34. else:
  35. if isinstance(error, commands.NoPrivateMessage):
  36. embed = discord.Embed(description="This command cannot be used in private messages.")
  37. elif isinstance(error, commands.DisabledCommand):
  38. embed = discord.Embed(description="This command is disabled.")
  39. elif isinstance(error, commands.CheckFailure):
  40. embed = discord.Embed(description="You do not have permission to do this. Back off, thot!")
  41. elif isinstance(error, commands.MissingRequiredArgument):
  42. embed = discord.Embed(description="Argument missing.")
  43. elif isinstance(error, commands.BadArgument):
  44. embed = discord.Embed(description="Invalid Argument given. Please check arguments given.")
  45. elif isinstance(error, commands.TooManyArguments):
  46. embed = discord.Embed(description="Too many arguments given.")
  47. elif isinstance(error, commands.CommandNotFound):
  48. cc = self.servers[str(ctx.guild.id)]["custom_commands"]
  49. if ctx.invoked_with in cc["1"]:
  50. embed = None
  51. elif len(ctx.message.content) < 6: # Should avoid puncutation emoticons while also not being big enough to trigger for mispelt commands,
  52. embed = None
  53. else:
  54. embed = discord.Embed(description="That Command doesn't exist.")
  55. elif isinstance(error, commands.BotMissingPermissions):
  56. embed = discord.Embed(description="I am missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
  57. elif isinstance(error, commands.MissingPermissions):
  58. embed = discord.Embed(description="You are missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
  59. elif isinstance(error, commands.NotOwner):
  60. embed = discord.Embed(description="You do not have permission to do this. You are not Roxie!")
  61. elif isinstance(error, commands.CommandOnCooldown):
  62. embed = discord.Embed(description="This command is on cooldown, please wait {} seconds before trying again.".format(error.retry_after))
  63. else:
  64. embed = discord.Embed(
  65. description="Placeholder embed. If you see this please message {}.".format(str(self.owner)))
  66. if embed:
  67. embed.colour = err_colour
  68. await ctx.send(embed=embed)
  69. def setup(bot_client):
  70. bot_client.add_cog(ErrHandle(bot_client))