如何生成可以在Discord.py中禁用的命令?

2024-05-03 06:20:48 发布

您现在位置:Python中文网/ 问答频道 /正文

我想知道是否有人知道如何使用其他命令禁用Discord.py命令。如果我们必须使用Json之类的东西,这并不重要,我只是想找到一种方法


Tags: 方法py命令jsondiscord
1条回答
网友
1楼 · 发布于 2024-05-03 06:20:48

command.update()与kwarg enabled一起使用

@bot.command()
async def foo(ctx):
    await ctx.send('whatever')


@foo.error
async def foo_error(ctx, error):
    """Simply an error handler"""
    if isinstance(error, commands.DisabledCommand):
        await ctx.send('Command is disabled')


@bot.command()
async def disable_foo(ctx):
    """Disabled the `foo` command"""
    foo.update(enabled=False)


@bot.command()
async def enable_foo(ctx):
    """Enables the `foo` command"""
    foo.update(enabled=True)

如果命令被禁用,commands.DisabledCommand将被抛出。 Reference

相关问题 更多 >