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