【问题标题】:Discord.py: How to get the colors of the roles?Discord.py:如何获取角色的颜色?
【发布时间】:2020-02-21 23:42:35
【问题描述】:

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

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

【问题讨论】:

    标签: discord.py discord.py-rewrite


    【解决方案1】:

    您可以使用.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

    【讨论】:

    • 感谢您的快速回复,但我收到错误,我修改了代码。你能检查我是否做错了什么吗? (我编辑了添加代码的问题)
    • 非常感谢,您解决了我的错误。祝你有美好的一天。
    猜你喜欢
    • 2021-06-02
    • 2021-05-05
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 2019-09-12
    • 1970-01-01
    • 2021-10-16
    • 2021-09-30
    相关资源
    最近更新 更多