Reputation: 11
if(msg.equalsIgnoreCase("hi")){
Member member = event.getMessage().getMentions().getMembers().get(0);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.cyan);
embedBuilder.setDescription("Hello, " + member.getUser().getName() + "!");
embedBuilder.build();
event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
message: hi @mentioned expected answer: hello @mention or name
Upvotes: 1
Views: 269
Reputation: 84
To get a mention of a member you can use member.getAsMention()
, in your case if you would like to actually mention someone, you would need to do it in the actual message (not the embed itself) as embeds do not support mentions and so it will be formatted in a weird way.
Alternatively you can just get the users name using member.getEffectiveName()
and prepend it with '@' so it would look like a mention, but won't actually mention anyone
Upvotes: 0
Reputation: 551
Get the user's ID and put it in between of <@
and >
. Example: <@355314189117554689>.
if (msg.equalsIgnoreCase("hi")) {
Member member = event.getMessage()
.getMentions()
.getMembers()
.get(0);
EmbedBuilder embedBuilder = new EmbedBuilder();
embedBuilder.setColor(Color.cyan);
// simply put the users snowflake ID between <@ and >
embedBuilder.setDescription("Hello, <@" + member.getUser().getId() + ">!");
embedBuilder.build();
event.getChannel().sendMessageEmbeds(embedBuilder.build()).queue();
}
Upvotes: 0