discord - 我怎样才能允许人们在 discord.py 中只踢低于他们角色的成员?
解决方案
您可以将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}.")