首页 > 解决方案 > 如何防止版主在 discord.py 中互相使用版主命令?

问题描述

我在 discord.py 中为我的服务器制作了一个机器人。它有审核命令。但我有一个问题。例如,如果我在主持人上使用静音命令。它给了他们一个沉默的角色。同样的事情也适用于踢/禁令。有什么办法可以阻止版主在其他模组上使用模组命令?

标签: pythondiscord.pybots

解决方案


您可以使用属性来比较用户>=top_role您尝试审核的成员相比的角色,如果您的权限低于您尝试审核的成员,它将阻止其余代码运行。这是一个简单的方法,

if member.top_role >= ctx.author.top_role:
    await ctx.send(f"You can only moderate members below your role")         
    return

这是一个将它与您想要的禁令或命令一起使用的示例,

@client.command()
@commands.has_permissions(ban_members = True)
async def ban(ctx, member: discord.Member):
    
    if member.top_role >= ctx.author.top_role:
        await ctx.send(f"You can only moderate members below your role")         
        return

    await member.ban()

推荐阅读