Interface Mentions
-
Method Summary
Modifier and TypeMethodDescription@Unmodifiable List<GuildChannel> An immutable list of all mentionedGuildChannels.<T extends GuildChannel>
@Unmodifiable List<T> getChannels(Class<T> clazz) An immutable list of all mentionedGuildChannelsof typeclazz.org.apache.commons.collections4.Bag<GuildChannel> ABagof mentioned channels.<T extends GuildChannel>
org.apache.commons.collections4.Bag<T> getChannelsBag(Class<T> clazz) ABagof mentioned channels of typeclazz.@Unmodifiable List<CustomEmoji> AllCustomEmojisused.org.apache.commons.collections4.Bag<CustomEmoji> ABagof custom emojis used.getJDA()The corresponding JDA instanceAn immutable list of all mentionedMembers.org.apache.commons.collections4.Bag<Member> ABagof mentionedMembers.@Unmodifiable List<IMentionable> getMentions(Message.MentionType... types) Combines all instances ofIMentionablefiltered by the specifiedMentionTypevalues.getRoles()An immutable list of all mentionedRoles.org.apache.commons.collections4.Bag<Role> ABagof mentioned roles.@Unmodifiable List<SlashCommandReference> An immutable list of all mentionedslash commands.org.apache.commons.collections4.Bag<SlashCommandReference> ABagof mentionedslash commands.getUsers()An immutable list of all mentionedUsers.org.apache.commons.collections4.Bag<User> ABagof mentionedUsers.booleanisMentioned(IMentionable mentionable, Message.MentionType... types) Checks if givenIMentionablewas mentioned in any way (@User, @everyone, @here, @Role).booleanIndicates if everyone is mentioned, by either using@everyoneor@here.
-
Method Details
-
getJDA
The corresponding JDA instance- Returns:
- The jda instance
-
mentionsEveryone
boolean mentionsEveryone()Indicates if everyone is mentioned, by either using@everyoneor@here.This is different from checking if
@everyoneis in the string, since mentions require additional flags to trigger.- Returns:
- True, if everyone is mentioned
-
getUsers
An immutable list of all mentionedUsers.
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
ABagof mentionedUsers.
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 be1, 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:
Bagof mentioned users- See Also:
-
getChannels
An immutable list of all mentionedGuildChannels.
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
ABagof mentioned channels.
This can be used to retrieve the amount of times a channel was mentioned.This may include GuildChannels from other
GuildsExample
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:
Bagof mentioned channels- See Also:
-
getChannels
An immutable list of all mentionedGuildChannelsof typeclazz.
If none were mentioned, this list is empty. Elements are sorted in order of appearance.This may include GuildChannels from other
GuildsExample
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- TheGuildChannelsub-classclass objectof the type of channel desired- Returns:
- Immutable list of mentioned GuildChannels that are of type
clazz. - Throws:
IllegalArgumentException- Ifclazzisnull
-
getChannelsBag
@Nonnull <T extends GuildChannel> org.apache.commons.collections4.Bag<T> getChannelsBag(@Nonnull Class<T> clazz) ABagof mentioned channels of typeclazz.
This can be used to retrieve the amount of times a channel was mentioned.This may include GuildChannels from other
GuildsExample
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- TheGuildChannelsub-classclass objectof the type of channel desired- Returns:
Bagof mentioned channels of typeclazz- Throws:
IllegalArgumentException- Ifclazzisnull- See Also:
-
getRoles
An immutable list of all mentionedRoles.
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
ABagof 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
GuildsExample
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:
Bagof mentioned roles- See Also:
-
getCustomEmojis
AllCustomEmojisused.
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
ABagof 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:
Bagof used custom emojis- See Also:
-
getMembers
An immutable list of all mentionedMembers.
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
PrivateChannelsandGroupChannels.- Returns:
- Immutable list of mentioned Members, or an empty list
-
getMembersBag
ABagof mentionedMembers.
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 be1, 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:
Bagof mentioned members- See Also:
-
getSlashCommands
An immutable list of all mentionedslash 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
ABagof mentionedslash 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:
Bagof mentioned slash commands- See Also:
-
getMentions
Combines all instances ofIMentionablefiltered by the specifiedMentionTypevalues.
If aMemberis available, it will be taken in favor of aUser. 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-MentionTypesto include- Returns:
- Immutable list of filtered
IMentionableinstances - Throws:
IllegalArgumentException- If provided withnull
-
isMentioned
Checks if givenIMentionablewas mentioned in any way (@User, @everyone, @here, @Role).
If no filteringMentionTypesare specified, all types are used.MentionType.HEREandMentionType.EVERYONEwill only be checked, if the givenIMentionableis of typeUserorMember.
Online status of Users/Members is NOT considered when checkingMentionType.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 withgetMentions(MentionType...)- Returns:
- True, if the given mentionable was mentioned in this message
-