Negative1
Negative1

Reputation: 11

how can I get the member mentioned and displayed in the embed

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

Answers (2)

Loso
Loso

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

rgnt
rgnt

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

Related Questions