Search code examples
pythondiscorddiscord.py

Discord.py: How to make embed role color the highest bot's color?


I want to make a profile command with discord.py and I want the embed message has bot's highest role colour.

My code:

@commands.command()
async def sanj(self, ctx, client, user: discord.Member = None):
    if user == None:
        user = ctx.author
    
    em = Embed(
        title = 'سنج',
        description = f"{user.mention} " + str(randrange(127)) + "% سنج هست",
        colour = client.top_role.colour
    )

    em.add_field(name="پـ.ـن", value="با کامند -help fun بقیه کامندای سنجش رو ببین")

    await ctx.reply(embed=em)

Solution

  • Use ctx.guild.me.top_role.colour. You also don't need to add client argument.

    @commands.command()
    async def sanj(self, ctx, user: discord.Member = None):
        if user == None:
            user = ctx.author
        
        em = Embed(
            title='سنج',
            description=f"{user.mention} " + str(randrange(127)) + "% سنج هست",
            colour=ctx.guild.me.top_role.colour
        )
    
        em.add_field(name="پـ.ـن", value="با کامند -help fun بقیه کامندای سنجش رو ببین")
    
        await ctx.reply(embed=em)