Resize my Image Blog

How to Make a Discord Bot Mention Users

Making a Discord bot mention users is one of the simplest features to add, but it is also one of the most useful. Mentions let your bot get someone’s attention, respond personally to commands, announce winners, assign responsibility, or create fun interactive messages. Whether you are building a moderation assistant, a game bot, a support tool, or a community engagement bot, learning how mentions work will help you make your bot feel more responsive and human.

TLDR: A Discord bot can mention a user by sending the user’s mention string, usually in the format <@USER_ID>. Most Discord libraries make this even easier with properties like user.toString() in Discord.js or member.mention in discord.py. Always be careful with permissions, user input, and allowed mentions so your bot does not spam or ping people unintentionally. For slash commands, the cleanest method is to accept a user option and include that selected user in the bot’s reply.

How Discord Mentions Work

Discord mentions are special text patterns that Discord converts into clickable, highlighted references. When you type @username in the Discord app, Discord internally stores that as a mention using the user’s unique ID. A user mention looks like this:

<@123456789012345678>

The long number is the user’s Discord user ID. Unlike usernames, user IDs do not change. That makes them the safest way for bots to refer to specific people. When your bot sends a message containing that mention format, Discord displays it as a normal mention and may notify the user, depending on their notification settings and the message’s allowed mentions.

There are several mention formats worth knowing:

For modern bots, <@USER_ID> is usually the right format for mentioning users. Many libraries also provide a convenient mention property, which is safer and easier than manually building the string.

Mentioning a User with Discord.js

If you are building your bot with Discord.js, mentioning users is straightforward. Discord.js objects often convert to mention strings automatically. For example, if you have a User or GuildMember object, you can include it directly in a message template.

Here is a simple example using a slash command where the bot mentions the user who ran the command:

await interaction.reply(`Hello ${interaction.user}!`);

In Discord.js, interaction.user becomes a mention-like string when placed inside a template literal. You can also be more explicit:

const userId = interaction.user.id;
await interaction.reply(`Hello <@${userId}>!`);

Both approaches can work, but using the library’s built-in user object is usually cleaner. If you want your bot to mention another user selected from a slash command option, you can do something like this:

const target = interaction.options.getUser('user');

await interaction.reply(`Hey ${target}, ${interaction.user} wanted to get your attention!`);

This is one of the most common patterns: the command user selects a target, and the bot mentions that target in the response.

Creating a Slash Command with a User Option

A good user mention command should avoid asking people to type raw IDs. Instead, let Discord handle user selection through slash command options. This provides a friendlier interface and reduces mistakes.

In Discord.js v14, a command definition might look like this:

const { SlashCommandBuilder } = require('discord.js');

module.exports = {
  data: new SlashCommandBuilder()
    .setName('poke')
    .setDescription('Mention a user with a friendly poke')
    .addUserOption(option =>
      option
        .setName('user')
        .setDescription('The user to mention')
        .setRequired(true)
    ),

  async execute(interaction) {
    const target = interaction.options.getUser('user');

    await interaction.reply(`👋 ${target}, you have been poked by ${interaction.user}!`);
  }
};

This creates a /poke command where users can choose someone from the server. The bot then replies with a message that mentions both the target and the person who used the command.

This approach is especially useful because Discord validates the selected user for you. You do not have to parse usernames, handle typos, or search through server members manually.

Mentioning Users with discord.py

If you prefer Python, discord.py offers a similarly simple way to mention users. Most user and member objects have a .mention property.

For a traditional prefix command, you might write:

from discord.ext import commands
import discord

bot = commands.Bot(command_prefix="!", intents=discord.Intents.default())

@bot.command()
async def hello(ctx, member: discord.Member):
    await ctx.send(f"Hello {member.mention}, {ctx.author.mention} says hi!")

With this command, a user can type something like:

!hello @Alex

The bot responds by mentioning Alex and the command author. The important part is member.mention, which gives you the correct mention string automatically.

For slash commands in discord.py, the code can look different depending on whether you are using the built-in app commands system or an extension. A simplified example using app_commands looks like this:

from discord import app_commands
import discord

class MyClient(discord.Client):
    def __init__(self):
        super().__init__(intents=discord.Intents.default())
        self.tree = app_commands.CommandTree(self)

client = MyClient()

@client.tree.command(name="wave", description="Wave at a user")
@app_commands.describe(member="The user to mention")
async def wave(interaction: discord.Interaction, member: discord.Member):
    await interaction.response.send_message(
        f"👋 Hello {member.mention}, {interaction.user.mention} is waving at you!"
    )

As with Discord.js, the best practice is to accept a real user or member option instead of plain text.

User Mentions vs Member Mentions

In Discord development, the difference between a User and a Member matters. A user is a global Discord account. A member is that user inside a specific server, including server-specific details such as nickname, roles, join date, and permissions.

If your bot only needs to mention someone, a user object is usually enough. But if your bot needs to check roles, moderation status, or server permissions before mentioning them, you probably need a member object.

For example, a moderation bot might only allow staff members to use a command that mentions a user. In that case, the bot should examine the command author’s guild member permissions before sending the message.

Using Allowed Mentions Safely

One of the most important concepts when making bots mention users is allowed mentions. Discord allows developers to control which mentions are actually parsed and pinged. This is crucial when your bot repeats user-generated content.

Imagine someone types this into a command:

/say hello @everyone

If your bot blindly repeats that message, it might ping the entire server. That can annoy members, violate server rules, and get your bot removed. Allowed mentions help prevent this.

In Discord.js, you can restrict mentions like this:

await interaction.reply({
  content: `Message for ${target}`,
  allowedMentions: {
    users: [target.id],
    roles: [],
    parse: []
  }
});

This tells Discord that only the specific target user should be mentioned. It prevents accidental parsing of other mentions in the message.

In discord.py, you can use discord.AllowedMentions:

await ctx.send(
    f"Message for {member.mention}",
    allowed_mentions=discord.AllowedMentions(users=True, roles=False, everyone=False)
)

If your bot sends content provided by users, you should almost always think about allowed mentions. It is a small detail that can prevent big problems.

Getting a User ID

Sometimes you may need to manually build a mention from a user ID. To get a user ID from Discord, enable Developer Mode in your Discord settings. Then right-click a user and choose Copy User ID.

Once you have the ID, you can create a mention like this:

<@123456789012345678>

However, manually storing user IDs should be done thoughtfully. If your bot saves IDs in a database for reminders, points, warnings, or subscriptions, make sure you store only what you need and respect user privacy. User IDs are not secret passwords, but they are still persistent identifiers.

Common Reasons Mentions Do Not Work

If your bot sends the mention text but it does not ping or display correctly, there are several possible causes:

Also remember that users can customize notification settings. Even if the mention is valid, the user may not receive a push notification if they have muted the server or adjusted their notification preferences.

Making Mentions Feel Natural

A bot that constantly pings people can become irritating quickly. The best Discord bots use mentions with purpose. Instead of mentioning users in every message, mention them when attention is genuinely needed.

For example, this is useful:

✅ <@123456789012345678>, your support ticket has been updated.

This is probably too noisy:

<@123456789012345678> you used a command!
<@123456789012345678> processing command!
<@123456789012345678> command complete!

A good rule is to mention users for actionable messages. If the user needs to respond, review something, claim a prize, or handle a task, a mention makes sense. If the message is just informational, consider using plain text or an embed without a ping.

Using Embeds with Mentions

Many bots use embeds because they look cleaner than plain text messages. You can include mentions in embed descriptions and fields, but be aware that mention behavior can vary depending on where the mention appears and how allowed mentions are configured.

In Discord.js, you might write:

const { EmbedBuilder } = require('discord.js');

const embed = new EmbedBuilder()
  .setTitle('Task Assigned')
  .setDescription(`${target} has been assigned a new task.`)
  .setColor(0x5865F2);

await interaction.reply({
  content: `${target}`,
  embeds: ,
  allowedMentions: { users: [target.id] }
});

Putting the mention in content as well as the embed is a common technique when you want to ensure the user is actually notified. The embed then provides the richer details.

Best Practices for Mention Commands

Before adding mention features to your bot, consider these practical guidelines:

  1. Use user options: Let Discord’s interface handle user selection.
  2. Limit mass mentions: Avoid allowing regular users to make the bot ping large groups.
  3. Validate permissions: Check whether the command author is allowed to mention someone for that purpose.
  4. Use allowed mentions: Prevent accidental @everyone, role, or unwanted user pings.
  5. Respect context: Do not mention users in channels they cannot access.
  6. Avoid spam: Add cooldowns to commands that ping people.

Cooldowns are especially helpful for playful commands like /poke, /hug, or /challenge. Fun commands can become annoying if one person uses them repeatedly to ping another member.

Final Thoughts

Making a Discord bot mention users is technically simple: send a message containing the right mention string or use your library’s built-in mention property. The real skill is knowing when and how to use mentions responsibly. A well-designed bot can make a server feel lively, organized, and interactive, while a careless bot can create noise and frustration.

Start with a simple slash command that accepts a user option, reply with that user’s mention, and then add safeguards such as permission checks, cooldowns, and allowed mentions. Once you understand these basics, you can use mentions for reminders, moderation logs, ticket updates, games, welcome messages, and much more. In the end, a mention is more than a ping; it is a way for your bot to bring the right person into the right conversation at the right moment.

Exit mobile version