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.

73 lines
3.2KB

  1. import traceback
  2. import datetime
  3. import discord
  4. from discord.ext import commands
  5. class ErrHandle:
  6. def __init__(self, bot_client):
  7. self.bot = bot_client
  8. self.dev = False # For debugging
  9. self.owner = self.bot.get_user(self.bot.owner_id)
  10. print(self.owner)
  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. print(self.owner)
  23. err_colour = 0x992d22
  24. if isinstance(error, commands.CommandInvokeError):
  25. if self.dev:
  26. raise error
  27. else:
  28. embed = discord.Embed(title=':x: Command Error', colour=err_colour) #Dark Red
  29. embed.add_field(name='Error', value=str(error))
  30. embed.add_field(name='Server', value=ctx.guild)
  31. embed.add_field(name='Channel', value=ctx.channel.mention)
  32. embed.add_field(name='User', value=ctx.author)
  33. embed.add_field(name='Message', value=ctx.message.content)
  34. embed.timestamp = datetime.datetime.utcnow()
  35. await self.owner.send(embed=embed)
  36. else:
  37. if isinstance(error, commands.NoPrivateMessage):
  38. embed = discord.Embed(description="This command cannot be used in private messages.")
  39. elif isinstance(error, commands.DisabledCommand):
  40. embed = discord.Embed(description="This command is disabled.")
  41. elif isinstance(error, commands.CheckFailure):
  42. embed = discord.Embed(description="You do not have permission to do this. Back off, thot!")
  43. elif isinstance(error, commands.MissingRequiredArgument):
  44. embed = discord.Embed(description="Argument missing.")
  45. elif isinstance(error, commands.BadArgument):
  46. embed = discord.Embed(description="Invalid Argument given. Please check arguments given.")
  47. elif isinstance(error, commands.TooManyArguments):
  48. embed = discord.Embed(description="Too many arguments given.")
  49. elif isinstance(error, commands.CommandNotFound):
  50. embed = discord.Embed(description="That Command doesn't exist.")
  51. elif isinstance(error, commands.BotMissingPermissions):
  52. embed = discord.Embed(description="I am missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
  53. elif isinstance(error, commands.MissingPermissions):
  54. embed = discord.Embed(description="You are missing the following permissions: {}".format(str(error.missing_perms).strip("[]")))
  55. elif isinstance(error, commands.NotOwner):
  56. embed = discord.Embed(description="You do not have permission to do this. You are not Roxie!")
  57. elif isinstance(error, commands.CommandOnCooldown):
  58. embed = discord.Embed(description="This command is on cooldown, please wait {} seconds before trying again.".format(error.retry_after))
  59. else:
  60. embed = discord.Embed(
  61. description="Placeholder embed. If you see this please message {}.".format(str(self.owner)))
  62. embed.colour = err_colour
  63. await ctx.send(embed=embed, delete_after=10)
  64. def setup(bot_client):
  65. bot_client.add_cog(ErrHandle(bot_client))