G
G
Goshujin2021-03-24 09:56:01
Python
Goshujin, 2021-03-24 09:56:01

How to display a list of user roles in Embed?

It is necessary that the bot displays the roles that the participant has. He does it, but crookedly: It is
605ae23a8590b710890544.png
necessary to make it so that he displays them by mention. How to do it?
Command code:

@Bot.command()
async def user(ctx):
    emb = discord.Embed(title = 'Информация о пользователе', color = 0xEE82EE)
    emb.set_thumbnail(url = ctx.message.author.avatar_url)
    emb.add_field(name = 'Присоеденился к серверу', value = ctx.message.author.joined_at.strftime('%d.%m.%Y %H:%M:%S'))
    emb.add_field(name = 'Присоеденился к Discord', value = ctx.message.author.created_at.strftime('%d.%m.%Y %H:%M:%S'))
    emb.add_field(name = 'Роли', value = ctx.message.author.roles)
    await ctx.send(embed = emb)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Nevzorov, 2021-03-24
@Goshujin

For now - your code shows the list of role objects as a string ( repr(role)).
Alternatively, you can use a generator/list comprehension to build a list of mentions in place, and str.join to join the whole list into one line:
", ".join(m.mention for m in ctx.author.roles)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question