【问题标题】:Discord python bot: How to make embed message with member's highest role Colour?Discord python bot:如何使用会员的最高角色颜色制作嵌入消息?
【发布时间】:2020-08-12 20:34:44
【问题描述】:

我想用 discord.py 创建一个配置文件命令,并且我希望嵌入消息具有成员的最高角色颜色。

我的代码:

@client.command(passContent=True)
@commands.has_role("????║Участники")
async def профиль(ctx, member: discord.Member):
    colour=member.Colour.default()
    профиль_сообщение=discord.Embed(
        title=f'Профиль {ctx.author.name}',
        colour=colour
        )
    await ctx.send(embed=профиль_сообщение)

错误:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: AttributeError: 'Member' object has no attribute 'Colour'

【问题讨论】:

标签: python discord.py


【解决方案1】:

这可以通过Member.top_role 并使用Role.colour 属性来完成

其他注意事项:

  • passContent 不是一个东西,它的 pass_context 但在重写时不需要这样做
@client.command()
@commands.has_role("?║Участники")
async def профиль(ctx, member: discord.Member):
    профиль_сообщение=discord.Embed(
        title=f'Профиль {ctx.author.name}',
        colour=member.top_role.colour
        )
    await ctx.send(embed=профиль_сообщение)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-04-29
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 2020-08-16
    • 2020-07-31
    • 2021-08-11
    • 2021-10-11
    相关资源
    最近更新 更多