Files
botpy/c/error.py
2025-11-29 19:58:47 +05:00

64 lines
1.9 KiB
Python

import discord
import traceback
import sys
from discord.ext import commands
class Error(commands.Cog):
def __init__(self,bot):
self.bot = bot
@commands.Cog.listener()
async def on_command_error(self, ctx, error):
if hasattr(ctx.command, "on_error"):
return
cog = ctx.cog
if cog:
if cog._get_overridden_method(cog.cog_command_error) is not None:
return
ignored = (commands.CommandNotFound,)
error = getattr(error, "original", error)
if isinstance(error, ignored):
return
if isinstance(error, commands.DisabledCommand):
await ctx.send(f"{ctx.command} has been disabled.")
elif isinstance(error, commands.NoPrivateMessage):
try:
await ctx.author.send(
f"{ctx.command} can not be used in Private Messages."
)
except discord.HTTPException:
pass
elif isinstance(error, commands.BadArgument):
if ctx.command.qualified_name == "tag list":
await ctx.send("I could not find that member. Please try again.")
elif isinstance(error, commands.MissingPermissions):
await ctx.reply("You don't have permissions to use this command")
elif isinstance(error, commands.NotOwner):
await ctx.reply("This command is only available to the bot owner")
else:
print(
"Ignoring exception in command {}:".format(ctx.command), file=sys.stderr
)
# traceback.print_exception(
# type(error), error, error.__traceback__, file=sys.stderr
# )
print(error)
@commands.Cog.listener()
async def on_ready(self):
print('Error cog has been loaded')
async def setup(bot):
await bot.add_cog(Error(bot))