Files
botpy/c/error.py
2025-11-26 19:34:08 +05:00

64 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
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("Ээм друк у тебя нет прав на использование этой команды!!")
elif isinstance(error, commands.NotOwner):
await ctx.reply("Эта команда доступна только владельцу бота!!!")
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))