嵌入无法正确显示

时间:2019-03-24 13:28:47

标签: python-3.x discord discord.py-rewrite

嗨,我在正确显示列表中遇到了一些问题。我试图将自己的角色放在一个列表标题下,这是我的列表如何在嵌入中显示自己的问题。

enter image description here

似乎每个角色都在列表标题下重复。

我尝试过inline=True,但这似乎无法解决问题。

     #--- Below is the list command ---

@commands.command(pass_context=True, no_pm=True, name='list', aliases=['roles', 'role'])
async def _list(self, ctx):
    """List of all available roles """
    guild = ctx.message.guild
    author = ctx.message.author
    botroom = self.bot.get_channel(555844758778544160) 
    intros = self.bot.get_channel(485381365366390796)
     #--- Role list Categories ---"
    Colours = ['Blue', 'Green', 'Orange', 'Yellow', 'Pink', 'Purple']
    Colours.sort(key=str.lower)

    Games = ['LoL', 'WoW', 'Overwatch']
    Games.sort(key=str.lower)

    Platforms = ['PC', 'Xbox', 'PS4', 'Nintendo Switch']
    Platforms.sort(key=str.lower)

    if ctx.message.channel == intros:
        pass
    else:
        if ctx.message.channel == botroom:
            title = '**Hey {}, here is a list of roles you can add:**'.format(author.display_name)
            embed = discord.Embed(title=title.format(), colour=0x0080c0)
            embed.add_field(name="**Have a role suggestion?**", value="If you can't find the role you want but would like to see it added to the roles list please tell us in <#555371532390760473>.", inline=False)
            embed.set_footer(text="Tip: to add a role from the list type the command !add/remove followed by the role.")

            #Lets start embed roles list below#
            for role in Games:
                embed.add_field(name="**Game Roles**", value="\n{} **({})**".format(role, len([member for member in guild.members if ([r for r in member.roles if r.name == role])])))

            for role in Platforms:
                embed.add_field(name="**Plaforms Roles**", value="\n{} **({})**".format(role, len([member for member in guild.members if ([r for r in member.roles if r.name == role])])))
            await ctx.send(embed=embed)
        else:
            await ctx.send('You can only use this command in {}.'.format(botroom.mention))

列表中的角色未按预期显示。

1 个答案:

答案 0 :(得分:2)

您当前为类别中的每个项目添加一次类别。相反,您希望一次添加每个类别,并在其下方列出所有角色。您还可以获取角色对象并直接访问len(role.members)

def role_name_to_summary(ctx, name):
    role = get(ctx.guild.roles, name=name)
    if not role:
        return None
    return f"{role.name} **({len(role.members)})**"

embed.add_field(name="**Game Roles**", value="\n".join(filter(None, [role_name_to_summary(ctx, name) for name in Games]))