JuicyBot_Base/handlers/errorHandling.py

42 lines
1.8 KiB
Python

import traceback
import sys
from discord.ext import commands
import discord
import configloader
class ErrorHandler(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
bot_app_info = await self.bot.application_info()
ignore_error = (commands.CommandNotFound, commands.UserInputError)
if isinstance(error, ignore_error):
return
elif isinstance(error, commands.CommandOnCooldown):
embed = configloader.embed.messageEmbed(f"This command is ratelimited, please try again in",
"{:.2f}s".format(error.retry_after),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.send(embed=embed)
elif isinstance(error, commands.NoPrivateMessage):
try:
embed = configloader.embed.messageEmbed(f"This Command can't be used in Private Messages.",
"{:.2f}s".format(ctx.command),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.author.send(embed=embed)
except:
pass
elif isinstance(error, commands.MissingPermissions):
embed = configloader.embed.messageEmbed(f"You don't have Permissions to use this command",
"{:.2f}s".format(ctx.command),
f"{bot_app_info.owner}", f"{bot_app_info.icon_url}")
return await ctx.send(embed=embed)
def setup(bot):
bot.add_cog(ErrorHandler(bot))