M
M
Maxim2021-09-17 14:48:54
Python
Maxim, 2021-09-17 14:48:54

How to use custom emoji in buttons in discord-components discord.py?

I want to insert an emoji from my server into a button, but I end up with an error. Help me please.

@bot.command(aliases = ['userinfo', 'ui'])
async def _userinfo( ctx, member: discord.Member = None ):
    if member is None:
        locale.setlocale(locale.LC_TIME, 'ru_RU')
        date_format = "%d %B %Y, %A"
        embed = discord.Embed(title=f'Информация об - {ctx.author}', colour=discord.Colour.from_rgb(0, 191, 255))
        embed.add_field(name='Ник:', value=f'{ctx.author.nick}', inline=False)
        embed.add_field(name='ID:', value=f'{ctx.author.id}', inline=False)
        embed.add_field(name='Аккаунт создан:', value=f'{ctx.author.created_at.strftime(date_format)}', inline=False)
        embed.add_field(name='Присоединился:', value=f'{ctx.author.joined_at.strftime(date_format)}', inline=False)
        embed2 = discord.Embed(title=f'Информация об - {ctx.author}', colour=discord.Colour.from_rgb(0, 191, 255))
        embed2.add_field(name='Статус:', value=f"{ctx.author.status}", inline=False)
        embed2.add_field(name='Репутация:', value=f'+{cursor.execute("SELECT rep FROM users WHERE id = {}".format(ctx.author.id)).fetchone()[0]}', inline=False)
        embed2.add_field(name='Роли:', value=f"{ctx.author.roles}", inline=False)
        embed2.add_field(name='Права:', value=f"{ctx.author}", inline=False)

        msg = await ctx.send(embed=embed,
            components=[
                Button(style=ButtonStyle.green, label=f"{left}", disabled=True),
                Button(style=ButtonStyle.green, label=f"{right}"),
                Button(style=ButtonStyle.red, label=f"{trash}")
            ]
        )

        response = await bot.wait_for("button_click")
        if response.channel == ctx.channel:
            if response.component.label == f"{right}":
                await msg.edit(embed=embed2)
            else:
                await response.respond(content="f")

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
TanderOFF, 2021-09-18
@D0ulink

I hope that friend

em1 = self.client.get_emoji(847880511841370132)
em2 = self.client.get_emoji(880885225935241278)
one = Button(style = ButtonStyle.blue, label = ' Главная  ', id='1', disabled = True, emoji=em1)
two = Button(style = ButtonStyle.blue, label = 'Инвентарь ', id='2' , emoji=em2)

V
Vindicar, 2021-09-17
@Vindicar

Where are the left, right, trash variables described?
Well, yes, do setlocale() once at the beginning of the program, not ten times in the middle.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question