I’m working on a Discord bot and I need to mention users so they get notified with a ping. Right now when I try to mention someone, it just shows up as plain text instead of creating an actual mention.
Here’s what I’m currently doing:
client.channels.cache.get(targetChannel).send(`@Username hello there!`);
The problem is that this just displays @Username as regular text without creating the blue highlight that actually pings the user. What’s the correct way to format user mentions in Discord bot messages so they work like real mentions?
yeah, others have covered it but don’t forget to check your bot’s permissions! you need the “mention everyone” perm for roles, but for just user mentions normal permissions are fine. also, make sure to manage cases when users leave the server!
For Discord bot mentions, don’t use the username directly. You need the user’s ID wrapped in angle brackets with an @ symbol: <@userId>. Here’s how your code should look: javascript client.channels.cache.get(targetChannel).send(`<@${userId}> hello there!`); This creates a proper mention that’ll actually notify the user. Grab the user ID from guild members or message events - using the numeric ID means your mentions won’t break if someone changes their username.
This is a common mistake for those new to Discord bot development. To mention a user properly, you can’t just use their username; you must use their user ID formatted as <@userID>. In practice, replace @Username with the user ID you obtain from the member object. For example, if you have a user object, you can send a message referencing them like this: javascript client.channels.cache.get(targetChannel).send(`<@${user.id}> hello there!`); This will create a functional mention that alerts the user, ensuring they receive the notification.