切换服务器受限命令

时间:2021-05-23 18:20:45

标签: discord discord.py bots

#f 垃圾邮件

async def on_message(message):
    if message.author.bot:
         return
    elif message.content.lower() == 'f':
        await message.channel.send('f')
    await bot.process_commands(message)

这是我当前的垃圾邮件代码,或者每次用户发送垃圾邮件时都会发送一个 f。 如果可能的话,我想让这个命令可切换并且服务器/公会受限。 例如有人说 !fspam 并且它被切换并关闭,当再次完成相同的操作时它被打开。或者它可能是 !fspam on/ !fspam off

1 个答案:

答案 0 :(得分:0)

您可以使用 Command.enable,您可以在其中使用 command.update。这将引发 DisabledCommand 错误。

另外请不要只是复制和粘贴代码,试着理解我做了什么。这将禁用所有公会。如果您希望每个服务器都使用它,那么您将需要使用一个数据库。

例如:

@client.command()
async def enable(ctx,*,command):
    command = client.get_command(command)
    command.update(enabled=True)
    await ctx.send(f"{command} enabled!")

@client.command()
async def disable(ctx,*,command):
    command = client.get_command(command)
    command.update(enabled=False)
    await ctx.send(f"{command} disabled!")