Discord.py: 如何获取角色的颜色?

Discord.py: How to get the colors of the roles?

我正在尝试制作我的第一个 discord 机器人。我想要实现的是获取服务器中所有角色的颜色。我怎样才能做到这一点?我进行了搜索,但只找到了如何设置角色的颜色,而不是如何获取当前颜色。预先感谢您的帮助。

@client.command()
async def roles_colors(ctx):
    for role in ctx.guild.roles:
        await ctx.send(role.name)
        await ctx.send(discord.role.color)

您可以使用 .colour 获取 discord.Role 对象的颜色。 https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Role.colour

您可以使用.roles获取discord.Guild对象的所有角色。 (不和谐公会是不和谐服务器。) https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Guild.roles

如果您的问题是如何获得 Discord 成员(具有多种颜色角色的成员)的呈现颜色,您只需访问 discord.Member 对象上的 .colour
https://discordpy.readthedocs.io/en/latest/api.html?highlight=roles#discord.Member.colour

编辑:

@client.command()
async def roles_colors(ctx):
    for role in ctx.guild.roles:
        await ctx.send(role.name)
        await ctx.send(role.color)

你写的discord.role.color,应该是role.color