Discord.py 重写角色层次结构检查 [英] Discord.py Rewrite Role Hierarchy Check

查看:29
本文介绍了Discord.py 重写角色层次结构检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 discord.py rewrite 中编写了一个机器人.到目前为止,它只有 !kick、!ban 和 !unban 等基本选项.但是,当前设置为具有适当权限的任何人都可以对任何人执行此操作.这意味着具有版主"级别的人可以禁止具有管理员"级别的人,这是不允许的.如何添加一个简单的检查来查看该人的排名是否高于/低于他们试图踢/禁止的人?

I have written a bot in discord.py rewrite. So far, it only has basic options such as !kick, !ban, and !unban. However, it is currently set up that anyone with the proper permissions can do this to anyone. This means that someone with the "Moderator" rank can ban someone with the "Admin" rank, which should not be allowed. How do I add a simple check to see if the person's rank is above/below the person they are trying to kick/ban?

推荐答案

Member 对象有一个top_role 属性,可以直接比较角色(角色越高越大"):

Member objects have a top_role attribute, and you can compare roles directly (higher roles are "larger"):

@bot.command()
async def ban(ctx, target: Member):
    if target.top_role >= ctx.author.top_role:
        await ctx.send("You can only ban people below you")
        return
    ...

这篇关于Discord.py 重写角色层次结构检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆