How to properly mention users in Discord bot using Java?

I’m working on a Discord bot in Java and I’m having trouble getting user mentions to work correctly. When I try to mention someone using their user ID in a regular string, it just shows up as plain text instead of creating an actual mention.

Here’s what I’ve tried so far:

textChannel.sendMessage("Hello @185729384950273024 can you help me?").queue();

This doesn’t create a clickable mention, it just displays the text exactly as written. I found their user ID by turning on developer mode in Discord settings, but I must be formatting it wrong somehow.

What’s the correct way to format user mentions in Discord bot messages? Is there a special syntax I need to use to make the mention work properly?

you gotta use <@185729384950273024> instead of just @185729384950273024. those tags are super important for it to be clickable. just make sure to format it right!

Here’s something that tripped me up when I started with JDA - test your mentions in a server where both your bot and the target user are actually there. I wasted hours debugging mention formatting when the real problem was trying to mention users who weren’t in the same guild. The <@userID> format looks fine in the message, but Discord won’t notify users outside that server. Also, watch out for cached User objects - IDs can go stale if someone leaves and rejoins.

Discord needs a specific format for mentions: wrap the user ID in angle brackets with @ prefix. Use <@userID> with no spaces. I hit this same problem building my guild bot - Discord’s parser only recognizes mentions with this exact format. Your code should be textChannel.sendMessage("Hello <@185729384950273024> can you help me?").queue();. This creates a proper mention that highlights their name and sends a notification. BTW, nickname mentions work too but use <@!userID> instead.

btw if ur still having issues, double check ur bot has permission to mention users in that channel. sometimes the mention format looks right but the bot can’t actually do it without proper permissions. also grab a fresh user ID from developer mode to make sure its valid.

The angle brackets are key here. Discord needs the exact format <@userID> for mentions to work. Your code should be:

textChannel.sendMessage("Hello <@185729384950273024> can you help me?").queue();

I found this out the hard way with my first bot last year. Skip the brackets and Discord just shows plain text instead of a mention. With the right format, the user gets notified and sees their name highlighted. Don’t put any spaces inside the brackets - it’ll break the mention.

Here’s something others missed - JDA’s User objects have a built-in user.getAsMention() method. No need to manually build the mention string since it automatically returns the correct <@userID> format. I’ve used this in production bots for months and it prevents formatting mistakes. If Discord ever changes how mentions work, JDA handles the update instead of you hunting down hardcoded strings everywhere. Same thing works with Member objects using member.getAsMention().

Yeah everyone’s got the format down, but manually managing mentions becomes a nightmare quickly. I’ve built tons of bots - the real headache starts when you need dynamic mentions from user interactions or database queries.

Rather than hardcoding mentions everywhere, I use Latenode flows to handle mention logic automatically. Someone joins a channel or triggers an event? Latenode grabs the user data and formats mentions correctly without me writing Java for every scenario.

Best part is connecting Discord webhooks to databases and other services through Latenode. Someone finishes a task in our project tool? It auto-mentions the right team members in Discord with proper <@userID> format.

No more repetitive mention code, everything’s centralized in one platform.