检查用户是否在完全不同的服务器中拥有角色

时间:2021-08-01 03:04:09

标签: python python-3.x discord discord.py

假设有人在具有相同机器人的随机服务器中使用命令,它将检测该用户是否在他们所在的不同服务器中具有特定角色。

谁能告诉我这是否可行?

1 个答案:

答案 0 :(得分:1)

您可以使用 commands.check 并使用其他公会的成员对象验证所需角色是否在 Member.roles 中。

这个函数会得到一个公会和那个公会中的角色,然后检查它是否在成员角色中

async def another_guild_role(ctx):
    guild = bot.get_guild(12345)    # change id here for wanted guild
    role = guild.get_role(12345)    # change id here for wanted role

    member = guild.get_member(ctx.author.id)
    # if member is not in bot chache make an API request
    if not member:
        member = guild.fetch_member(ctx.author.id)

    return role in member.roles

这是将它包含在命令中的方式。

@bot.command()
@commands.check(another_guild_role)
async def test(ctx):
    await ctx.send("Yes you have the role")