I’m working on my Java Discord bot and I’ve hit a snag with mentioning users. I learned that using a user’s ID is recommended over their name, so I enabled developer mode to grab the correct ID. Here’s what I tried:
messageChannel.sendAnnouncement("Hi <@987654321098765432>, are you around?").execute();
Unfortunately, the bot sends the message as plain text instead of a real @mention. I’m puzzled because I’ve followed the usual guidelines. Has anyone dealt with this issue before or know the proper format for mentions in Java Discord bots? Any help would be greatly appreciated!
I ran into this exact problem when I was first starting out with Discord bots in Java. The trick is to use the proper mention syntax for Discord’s API. Instead of using angle brackets, you need to wrap the user ID in <@!ID> format. Here’s what worked for me:
messageChannel.sendMessage("Hey <@!987654321098765432>, got a sec?").queue();
This should properly trigger the mention. Also, make sure you’re using the correct channel type for sending messages. If you’re in a text channel, sendMessage()
is the way to go rather than sendAnnouncement()
.
One last tip: always test your mentions in a private channel first to avoid accidentally pinging people repeatedly while debugging. Good luck with your bot!
I’ve encountered this issue before. The problem lies in how you’re constructing the mention. Instead of using angle brackets, Discord’s API requires a specific format for mentions. Try this approach:
messageChannel.sendMessage("Hey <@987654321098765432>, got a moment?").queue();
Notice the lack of ‘!’ in the mention format. This should correctly trigger the mention. Also, use sendMessage()
for regular text channels rather than sendAnnouncement()
.
If you’re using JDA, another clean method is:
messageChannel.sendMessage(jda.getUserById("987654321098765432").getAsMention() + ", are you available?").queue();
This retrieves the User object and generates the correct mention format automatically. Hope this helps with your bot development!
hey john, had similar issue. try using User
object instead of raw ID. something like:
User user = jda.getUserById(\"987654321098765432\"); messageChannel.sendMessage(user.getAsMention() + \", you there?\").queue();
should work. lmk if u need more help!