如何制作可以在 Discord.py 中禁用的命令?

时间:2020-12-18 19:28:20

标签: python discord discord.py

我想知道是否有人知道如何制作可以用另一个命令禁用的 Discord.py 命令。如果我们必须使用Json之类的东西并不重要,我只是想要一种方式。

1 个答案:

答案 0 :(得分:2)

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