Discord.py discord:在特定角色列表中的最高角色

Discord.py discord:在特定角色列表中的最高角色,discord.py,Discord.py,如何在某些角色中扮演用户的最高角色? 例如,我有这类角色: 我希望当我去查看用户信息时,其中最高的角色会出现?您可以反转成员。角色并找到第一个匹配项: @bot.command() async def my_highest_role(ctx): highest = discord.utils.find(lambda role: role in my_roles, reversed(ctx.author.roles)) if highest: await ctx.

如何在某些角色中扮演用户的最高角色? 例如,我有这类角色:


我希望当我去查看用户信息时,其中最高的角色会出现?

您可以反转
成员。角色
并找到第一个匹配项:

@bot.command()
async def my_highest_role(ctx):
    highest = discord.utils.find(lambda role: role in my_roles, reversed(ctx.author.roles))
    if highest:
        await ctx.send(highest.name)
    else:
        await ctx.send("No such role")

member.top_角色是,但在我想要的特定角色中,用户no的角色最高