text: import logging
  from asyncio import sleep
  
  from discord.ext.commands import Cog
  from discord.ext.commands import (
      BadArgument,
      CommandNotFound,
      CheckFailure,
      CommandOnCooldown,
      BotMissingPermissions,
      MissingRequiredArgument
  )
  
  from bot.utils import ErrorEmbed, HelpEmbed
  
  
  log = logging.getLogger(__name__)
  
  class GlobalErrorHandler(Cog):
      def __init__(self, bot):
          self.bot = bot
  
      @Cog.listener()
      async def on_command_error(self, ctx, error):
          if isinstance(error, CommandNotFound):
              pass
          
          elif isinstance(error, BotMissingPermissions):
              cmd = ctx.command
              perms = ', '.join([_.replace('_', ' ').replace('guild', 'server').title() for _ in error.missing_perms])
              await ctx.send(embed=ErrorEmbed(description=f'I\'m missing the following permissions: {perms}'))
              log.info(f'[{cmd.qualified_name}] bot missing permissions. Author: {ctx.author} ({ctx.author.id}): {perms}')    
  
          elif isinstance(error, CheckFailure):
              pass
  
          elif isinstance(error, MissingRequiredArgument):
              await ctx.send(embed=HelpEmbed(ctx, ctx.command))
  
          elif isinstance(error, BadArgument):
              pass     
  
          elif isinstance(error, CommandOnCooldown):
              cmd = ctx.command
              await ctx.send(embed=ErrorEmbed(description=f'You are on cooldown!').set_footer(text=f'You can use this command again in {round(cmd.get_cooldown_retry_after(ctx))} seconds'), delete_after=5)
              log.info(f'[{cmd.qualified_name}] command cooldown reached. Author: {ctx.author} ({ctx.author.id})')
              await sleep(5)
              try: await ctx.message.delete()
              except: pass # LMFAO writing code like this is a crime
  
          else:
              if ctx.command is not None and ctx.command.has_error_handler:
                  return
  
              if ctx.cog is not None and ctx.cog.has_error_handler:
                  return
                  
              log.error(error)
              await ctx.send(f'Unhandled error! ```{error}```')
              raise error
  
  def setup(bot):
      bot.add_cog(GlobalErrorHandler(bot))