I am making simple Discord bot for my server, because part of one bot doesn't work. But, that bot needs to tag people from one role (let's say that role is "Moderator"). I wanted it to tag everyone from Moderator role, which will be like @Moderator. Here is my code (I am using Python 3.6):
if message.content.startswith('!startbot'):
msg = '@Moderator, (some message after this)'.format(message)
But, that "@Moderator" doesn't actually tag anyone from Moderator role. It's just blank text like every other message. But, when I as someone real from Discord server type @Moderator, it brings red color (which I set) and it tags Moderator.
Can someone help me please to solve this thing ?
Role mentions in Discord are triggered like this:
<@&ROLE_ID>
Where ROLE_ID is the ID of the role you are trying to mention. Get the ID of the Moderators role, add it to the string accordingly and the bot will mention the role as you would from the Discord client.
This method also works for webhooks.
Mentioning in embeds requires a special format. The easiest way to do so is by consulting the following table:
Type | Structure | Example | Output |
---|---|---|---|
User | <@USER_ID> |
<@80351110224678912> |
|
User (Nickname) | <@!USER_ID> |
<@!80351110224678912> |
|
Channel | <#CHANNEL_ID> |
<#103735883630395392> |
|
Role | <@&ROLE_ID> |
<@&165511591545143296> |
|
Custom Emoji | <:NAME:ID> |
<:mmLol:216154654256398347> |
|
Custom Emoji (Animated) | <:a:NAME:ID> |
<a:nyancat:392938283556143104> |
|
Unix Timestamp | <t:TIMESTAMP> |
<t:1618953630> |
|
Unix Timestamp (Styled) | <t:TIMESTAMP:STYLE> |
<t:1618953630:d> |
Taken from the Discord API Docs
Assuming you are using the current stable version of discord.py
Per documentation, the role object has a method named mention
. So all you need to do is
msg = '{} ...'.format(role.mention)
To obtain the role object you probably need to iterate over the server's available roles and find the role object you are looking for
You have to get the role object first. To do this just do:
moderator = discord.utils.get(ctx.guild.roles, id=moderator_role_id_here)
The just send a message
await ctx.send(f'Hello {moderator.mention}')
It will tag all users with this role.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With