如何检查用户是否在特定服务器中具有特定角色

How can you check if a user has a particular role in a particular server

我想为我的机器人制作 Patreon Only 命令,但我不知道如何制作它,所以我可以限制对基于 1 个服务器中的 1 个角色的命令的访问,我希望该命令在全球范围内工作,但我希望在我的支持服务器上担任“Patreon”角色的人只能访问该命令。

在您的命令中,使用 get_guild to get your support server guild, then Guild.get_member to get the member object of whoever is executing the command (ctx.author.id). You can then check if your Patreon role is in that member's Member.roles (I would use utils.get),否则退出命令。

您可以使用 discord.utils.get 获取 Patreon 角色,然后遍历成员的角色和一个简单的 if-else.

@client.command()
async def test(ctx):
    homeGuild = client.get_guild(7300646418576xxxxx)  # Home Guild/Support Server; where user has "Patreon" role.
    patreonRole = get(homeGuild.roles, id=7570088168301xxxxx)  # Patreon role ID that a user must have.
    member = []

    for pledger in homeGuild.members:
        if pledger == ctx.author:
            member = pledger

    if patreonRole in member.roles:
        await ctx.send("You are a Patreon.")
    else:
        await ctx.send("You are not a Patreon.")