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.

75 lines
3.4KB

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