【问题标题】:How to whitelist roles from being banned如何将角色列入白名单以防止被禁止
【发布时间】:2021-07-02 22:36:21
【问题描述】:

我之前问过这个问题,但由于我对堆栈溢出的经验几乎为零,所以它搞砸了。所以我会用 anwser 重写这个问题,这样寻找这个的人就可以马上得到它。

所以我的问题是,我如何才能将角色列入白名单以防止被禁止。现在稍后,随着对 discord.py 的更多经验,我可以告诉你下面列出的答案是这样做的方法。

工作代码:感谢 CaptAngryEyes

@bot.command()
async def ban(ctx, member : discord.Member):
    whitelisted_roles = [728345678923456, 923478569378456, 8923475627893456] # Put the role IDs here
    for role in member.roles:
        if role.id in whitelisted_roles:
            await ctx.send("You can't ban this user! He is a moderator!")
            return
        else:
            # Ban code goes here...
            pass

【问题讨论】:

  • 如果没有最小的代码工作示例,将很难为您提供帮助。

标签: python discord discord.py whitelist


【解决方案1】:

您可以遍历用户的角色并检查他是否在列表中具有角色。我使用角色 ID,因为它无法更改。

@bot.command()
async def ban(ctx, member : discord.Member):
    whitelisted_roles = [728345678923456, 923478569378456, 8923475627893456] # Put the role IDs here
    for role in member.roles:
        if role.id in whitelisted_roles:
            await ctx.send("You can't ban this user! He is a moderator!")
            return
        else:
            # Ban code goes here...
            pass

如果他具有“白名单”角色,我们将不返回任何内容并且命令结束。

【讨论】:

    猜你喜欢
    • 2020-05-11
    • 1970-01-01
    • 2022-08-21
    • 1970-01-01
    • 2012-05-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-09-01
    相关资源
    最近更新 更多