Python 我无法在discord.py中的自定义检查中引发错误

Python 我无法在discord.py中的自定义检查中引发错误,python,error-handling,discord.py,Python,Error Handling,Discord.py,我必须在discord bot中的自定义检查中引发自定义错误 我有以下代码: class CommandDisabled(commands.CheckFailure): pass def check_enabled(ctx): db = firebase.database() isEnabled = db.child('Disabled').child(str(ctx.guild.id)).child(ctx.command).get() if isEnabled

我必须在discord bot中的自定义检查中引发自定义错误

我有以下代码:

class CommandDisabled(commands.CheckFailure):
    pass
def check_enabled(ctx):
    db = firebase.database()
    isEnabled = db.child('Disabled').child(str(ctx.guild.id)).child(ctx.command).get()
    if isEnabled.val() is None:
        return isEnabled.val() is None
    else:
        raise CommandDisabled
        return isEnabled.val() is None

@commands.command(name="seen",aliases=["lastseen","last"])
@commands.check(check_enabled)
async def _seen(self,ctx:commands.Context,user:discord.Member):
    db = firebase.database()
    seen_data = db.child("Last Seen").child(str(user.id)).get()
    if seen_data.val() is None:
        await ctx.send("**I have not seen that user so far.**")
    else:
        time = seen_data.val()["Time"]
        time_seen = datetime.strptime(time, "%Y-%m-%d %H:%M:%S.%f")
        final_time = datetime.utcnow()-time_seen
        total_min = round((final_time.total_seconds())/60)
        temp = 0
        while total_min >= 60:
            total_min -= 60
            temp += 1
        minutes = total_min-temp*(60)
        if temp == 0:
            em = discord.Embed(description=f"**`{user.name}` was last seen `{minutes} minutes` ago.**",color=discord.Color.random())
            await ctx.send(embed=em)
        else:
            em = discord.Embed(description=f"**`{user.name}` was last seen more than `{temp} hours` ago.**",color=discord.Color.random())
            await ctx.send(embed=em)
现在我在check_enabled函数中提出CommandDisabled错误。然后我按如下方式处理:

@commands.Cog.listener()
async def on_command_error(self,ctx,error):
    if isinstance(error, CommandDisabled):
        em = discord.Embed(description="This command is disabled in your      server. Ask admin to enable it",color=discord.Color.random())
        await ctx.send(embed=em)
但是它不工作,我想发送的嵌入不工作。命令只是停止工作,但通知它已禁用的嵌入不会被发送

这个代码在一个齿轮内


请帮助我。

尝试在错误处理程序中打印错误错误处理程序不起作用idk为什么我尝试在错误处理程序中打印“是”,但什么也没有发生您可以在问题中包含错误处理程序吗?我包含了错误处理程序,正如您所说,尝试删除错误处理程序,并检查是否在终端中打印CommandDisabled,如果未打印,则检查功能中断