【问题标题】:How can I allow people to only kick members lower than their role with discord.py?我怎样才能允许人们使用 discord.py 只踢低于其角色的成员?
【发布时间】:2021-06-15 23:41:58
【问题描述】:

我正在尝试使用 Python 和 discord.py 库创建一个 kick 命令,但我不知道如何让人们只能踢低于其角色的成员,因此版主将无法踢管理员。

enter image description here

【问题讨论】:

  • 请不要包含您的代码图像,请使用markdown 格式化。当其他人遇到同样的问题时,添加图片会使其难以显示。

标签: discord discord.py discord.net


【解决方案1】:

您可以将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}.")

【讨论】:

  • @Had 如果它帮助你/正在工作,请确保接受答案。
  • 版主可以用这个踢其他版主,如果你不希望这种情况发生,请严格比较>
【解决方案2】:

将所有版主添加到一个列表中,将普通用户添加到另一个列表中。

像这样;

string[] moderator = all moderators. 
string[] regularUsers = all regular users.

【讨论】:

  • 说明不清楚,这也不能回答我的问题...
  • 我认为@Videl 是在告诉您将所有版主 id 存储为一个列表并将所有管理员存储为一个列表,因此您知道版主何时试图踢管理员,不建议这样做.它非常非pythonic,以后会引发几个问题
猜你喜欢
  • 1970-01-01
  • 2021-06-03
  • 1970-01-01
  • 2012-08-13
  • 1970-01-01
  • 1970-01-01
  • 2012-12-20
  • 2022-10-23
  • 2020-09-06
相关资源
最近更新 更多