Interface Mentions


public interface Mentions
Interface to access the mentions of various entities.
  • Method Details

    • getJDA

      @Nonnull JDA getJDA()
      The corresponding JDA instance
      Returns:
      The jda instance
    • mentionsEveryone

      boolean mentionsEveryone()
      Indicates if everyone is mentioned, by either using @everyone or @here.

      This is different from checking if @everyone is in the string, since mentions require additional flags to trigger.

      Returns:
      True, if everyone is mentioned
    • getUsers

      @Nonnull List<User> getUsers()
      An immutable list of all mentioned Users.
      If no user was mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the user and not mentions through roles or everyone mentions.

      This might also contain users which are not present in getMembers().

      Returns:
      Immutable list of mentioned users
    • getUsersBag

      @Nonnull org.apache.commons.collections4.Bag<User> getUsersBag()
      A Bag of mentioned Users.
      This can be used to retrieve the amount of times a user was mentioned. This only counts direct mentions of the user and not mentions through roles or everyone mentions. The count may be 1, if the user was mentioned through a message reply.

      This might also contain users which are not present in getMembers().

      Example

      
       void sendCount(Message msg)
       {
           List<User> mentions = msg.getMentions().getUsers(); // distinct list, in order of appearance
           Bag<User> count = msg.getMentions().getUsersBag();
           StringBuilder content = new StringBuilder();
           for (User user : mentions)
           {
               content.append(user.getAsTag())
                      .append(": ")
                      .append(count.getCount(user))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of mentioned users
      See Also:
    • getChannels

      @Nonnull List<GuildChannel> getChannels()
      An immutable list of all mentioned GuildChannels.
      If none were mentioned, this list is empty. Elements are sorted in order of appearance.

      This may include GuildChannels from other Guilds

      Returns:
      Immutable list of mentioned GuildChannels
    • getChannelsBag

      @Nonnull org.apache.commons.collections4.Bag<GuildChannel> getChannelsBag()
      A Bag of mentioned channels.
      This can be used to retrieve the amount of times a channel was mentioned.

      This may include GuildChannels from other Guilds

      Example

      
       void sendCount(Message msg)
       {
           Bag<GuildChannel> mentions = msg.getMentions().getChannelsBag();
           StringBuilder content = new StringBuilder();
           for (GuildChannel channel : mentions.uniqueSet())
           {
               content.append("#")
                      .append(channel.getName())
                      .append(": ")
                      .append(mentions.getCount(channel))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of mentioned channels
      See Also:
    • getChannels

      @Nonnull <T extends GuildChannel> List<T> getChannels(@Nonnull Class<T> clazz)
      An immutable list of all mentioned GuildChannels of type clazz.
      If none were mentioned, this list is empty. Elements are sorted in order of appearance.

      This may include GuildChannels from other Guilds

      Example

      
       List<GuildMessageChannel> getCoolMessageChannels(Message msg)
       {
           List<GuildMessageChannel> channels = msg.getMentions().getChannels(GuildMessageChannel.class);
           return channels.stream()
               .filter(channel -> channel.getName().contains("cool"))
               .collect(Collectors.toList());
       }
       
      Parameters:
      clazz - The GuildChannel sub-class class object of the type of channel desired
      Returns:
      Immutable list of mentioned GuildChannels that are of type clazz.
      Throws:
      IllegalArgumentException - If clazz is null
    • getChannelsBag

      @Nonnull <T extends GuildChannel> org.apache.commons.collections4.Bag<T> getChannelsBag(@Nonnull Class<T> clazz)
      A Bag of mentioned channels of type clazz.
      This can be used to retrieve the amount of times a channel was mentioned.

      This may include GuildChannels from other Guilds

      Example

      
       void sendCount(Message msg)
       {
           Bag<GuildMessageChannel> mentions = msg.getMentions().getChannelsBag(GuildMessageChannel.class);
           StringBuilder content = new StringBuilder();
           for (GuildMessageChannel channel : mentions.uniqueSet())
           {
               content.append("#")
                      .append(channel.getName())
                      .append(": ")
                      .append(mentions.getCount(channel))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Parameters:
      clazz - The GuildChannel sub-class class object of the type of channel desired
      Returns:
      Bag of mentioned channels of type clazz
      Throws:
      IllegalArgumentException - If clazz is null
      See Also:
    • getRoles

      @Nonnull List<Role> getRoles()
      An immutable list of all mentioned Roles.
      If none were mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the role and not mentions through everyone mentions.

      This may include Roles from other Guilds

      Returns:
      immutable list of mentioned Roles
    • getRolesBag

      @Nonnull org.apache.commons.collections4.Bag<Role> getRolesBag()
      A Bag of mentioned roles.
      This can be used to retrieve the amount of times a role was mentioned. This only counts direct mentions of the role and not mentions through everyone mentions.

      This may include Roles from other Guilds

      Example

      
       void sendCount(Message msg)
       {
           List<Role> mentions = msg.getMentions().getRoles(); // distinct list, in order of appearance
           Bag<Role> count = msg.getMentions().getRolesBag();
           StringBuilder content = new StringBuilder();
           for (Role role : mentions)
           {
               content.append(role.getName())
                      .append(": ")
                      .append(count.getCount(role))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of mentioned roles
      See Also:
    • getCustomEmojis

      @Nonnull List<CustomEmoji> getCustomEmojis()
      All CustomEmojis used.
      This only includes Custom Emojis, not unicode Emojis. These are not the same as the unicode emojis that Discord also supports. Elements are sorted in order of appearance.

      Unicode emojis are not included as CustomEmojis!

      Returns:
      An immutable list of the Custom Emojis used (example match <:jda:230988580904763393>)
    • getCustomEmojisBag

      @Nonnull org.apache.commons.collections4.Bag<CustomEmoji> getCustomEmojisBag()
      A Bag of custom emojis used.
      This can be used to retrieve the amount of times an emoji was used.

      Example

      
       void sendCount(Message msg)
       {
           List<CustomEmoji> emojis = msg.getMentions().getCustomEmojis(); // distinct list, in order of appearance
           Bag<CustomEmoji> count = msg.getMentions().getCustomEmojisBag();
           StringBuilder content = new StringBuilder();
           for (CustomEmoji emoji : emojis)
           {
               content.append(emojis.getName())
                      .append(": ")
                      .append(count.getCount(emoji))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of used custom emojis
      See Also:
    • getMembers

      @Nonnull List<Member> getMembers()
      An immutable list of all mentioned Members.
      If none were mentioned, this list is empty. Elements are sorted in order of appearance. This only counts direct mentions of the role and not mentions through everyone mentions.

      This is always empty in PrivateChannels.

      Returns:
      Immutable list of mentioned Members, or an empty list
    • getMembersBag

      @Nonnull org.apache.commons.collections4.Bag<Member> getMembersBag()
      A Bag of mentioned Members.
      This can be used to retrieve the amount of times a user was mentioned. This only counts direct mentions of the member and not mentions through roles or everyone mentions. The count may be 1, if the user was mentioned through a message reply.

      Example

      
       void sendCount(Message msg)
       {
           List<Member> mentions = msg.getMentions().getMembers(); // distinct list, in order of appearance
           Bag<Member> count = msg.getMentions().getMembersBag();
           StringBuilder content = new StringBuilder();
           for (Member user : mentions)
           {
               content.append(member.getUser().getAsTag())
                      .append(": ")
                      .append(count.getCount(member))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of mentioned members
      See Also:
    • getSlashCommands

      @Nonnull List<SlashCommandReference> getSlashCommands()
      An immutable list of all mentioned slash commands.
      If none were mentioned, this list is empty. Elements are sorted in order of appearance.

      Be aware these mentions could be mentioning a non-existent command

      Returns:
      Immutable list of mentioned slash commands, or an empty list
    • getSlashCommandsBag

      @Nonnull org.apache.commons.collections4.Bag<SlashCommandReference> getSlashCommandsBag()
      A Bag of mentioned slash commands.
      This can be used to retrieve the amount of times a slash commands was mentioned.

      Be aware these mentions could be mentioning a non-existent command

      Example

      
       void sendCount(Message msg)
       {
           List<SlashCommandReference> mentions = msg.getMentions().getSlashCommands(); // distinct list, in order of appearance
           Bag<SlashCommandReference> count = msg.getMentions().getSlashCommandsBag();
           StringBuilder content = new StringBuilder();
           for (SlashCommandReference commandRef : mentions)
           {
               content.append(commandRef.getAsMention())
                      .append(": ")
                      .append(count.getCount(commandRef))
                      .append("\n");
           }
           msg.getChannel().sendMessage(content.toString()).queue();
       }
       
      Returns:
      Bag of mentioned slash commands
      See Also:
    • getMentions

      Combines all instances of IMentionable filtered by the specified MentionType values.
      If a Member is available, it will be taken in favor of a User. This only provides either the Member or the User instance, rather than both.

      If no MentionType values are given, all types are used.

      Parameters:
      types - MentionTypes to include
      Returns:
      Immutable list of filtered IMentionable instances
      Throws:
      IllegalArgumentException - If provided with null
    • isMentioned

      boolean isMentioned(@Nonnull IMentionable mentionable, @Nonnull Message.MentionType... types)
      Checks if given IMentionable was mentioned in any way (@User, @everyone, @here, @Role).
      If no filtering MentionTypes are specified, all types are used.

      MentionType.HERE and MentionType.EVERYONE will only be checked, if the given IMentionable is of type User or Member.
      Online status of Users/Members is NOT considered when checking MentionType.HERE.

      Parameters:
      mentionable - The mentionable entity to check on.
      types - The types to include when checking whether this type was mentioned. This will be used with getMentions(MentionType...)
      Returns:
      True, if the given mentionable was mentioned in this message