python - 如何防止版主在 discord.py 中互相使用版主命令?
问题描述
我在 discord.py 中为我的服务器制作了一个机器人。它有审核命令。但我有一个问题。例如,如果我在主持人上使用静音命令。它给了他们一个沉默的角色。同样的事情也适用于踢/禁令。有什么办法可以阻止版主在其他模组上使用模组命令?
解决方案
您可以使用属性来比较用户>=
与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()
推荐阅读
- celery - 使用 sqs 代理进行 celery 监控
- javascript - 如何将选择标签文本添加到输入中?
- tcl - TCL regsub 使用 RegEx 匹配作为关联数组中的索引
- javascript - 我无法在 vue 中打印 v-img 的图像
- amazon-web-services - 需要访问节点上的文件“etc/origin/master/master-config.yaml”?#istio
- laravel - Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 此路由不支持 POST 方法。支持的方法:GET、HEAD
- shell - 如何在使用 ssh 时退出整个 shell 脚本
- angular - 为什么小吃店的颜色没有变化?
- python - 为什么 setuptools 这么慢
- scala - Scala 库不兼容