我怎样才能允许人们只踢低于他们 discord.py 角色的成员?
How can I allow people to only kick members lower than their role with discord.py?
我正在尝试使用 Python 和 discord.py 库创建踢出命令,但我不知道如何让人们只能踢出低于其角色的成员,所以版主不能踢管理员。
enter image description here
将所有版主添加到一个列表,将普通用户添加到另一个列表。
像这样;
string[] moderator = all moderators.
string[] regularUsers = all regular users.
您可以将 Member
对象与名为 top_role
的函数进行比较
示例代码为:
@client.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
if member.top_role >= ctx.author.top_role: # Check if the role is below the authors role
await ctx.send("You can only kick users with a lower role!")
return
else:
await member.kick(reason=reason)
await ctx.send(f"{member.id} got kicked with the reason: {reason}.")
我正在尝试使用 Python 和 discord.py 库创建踢出命令,但我不知道如何让人们只能踢出低于其角色的成员,所以版主不能踢管理员。
enter image description here
将所有版主添加到一个列表,将普通用户添加到另一个列表。
像这样;
string[] moderator = all moderators.
string[] regularUsers = all regular users.
您可以将 Member
对象与名为 top_role
示例代码为:
@client.command()
@commands.has_permissions(kick_members=True)
async def kick(ctx, member: discord.Member, *, reason=None):
if member.top_role >= ctx.author.top_role: # Check if the role is below the authors role
await ctx.send("You can only kick users with a lower role!")
return
else:
await member.kick(reason=reason)
await ctx.send(f"{member.id} got kicked with the reason: {reason}.")