T
T
tatsuki12021-10-29 23:37:05
Python
tatsuki1, 2021-10-29 23:37:05

How to mention a role by name?

Greetings. Very easy question, and very stupid me. In general, I need to mention the role exactly by name, or, create it, take its id, and mention it. Help me please.
ps library discord.py

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
RealSosiso4ka, 2021-10-30
@tatsuki1

I didn’t quite understand the essence of the question, but here is the code that allows you to mention the role by name:

@bot.command()
async def mention_role(ctx, role_name):
    server = ctx.guild
    role = discord.utils.get(server.roles, name=role_name)
    await ctx.send(role.mention)

You enter the command mention_role (with your prefix, of course) and the name of the role. The bot will send you a message mentioning this role.
Example:
User enters: .mention_role Moderator
Bot outputs the message: @Moderator

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question