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 mentionedGuildChannels
of typeclazz
.org.apache.commons.collections4.Bag<GuildChannel>
ABag
of mentioned channels.<T extends GuildChannel>
org.apache.commons.collections4.Bag<T>getChannelsBag
(Class<T> clazz) ABag
of mentioned channels of typeclazz
.@Unmodifiable List<CustomEmoji>
AllCustomEmojis
used.org.apache.commons.collections4.Bag<CustomEmoji>
ABag
of custom emojis used.getJDA()
The corresponding JDA instanceAn immutable list of all mentionedMembers
.org.apache.commons.collections4.Bag<Member>
ABag
of mentionedMembers
.@Unmodifiable List<IMentionable>
getMentions
(Message.MentionType... types) Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.getRoles()
An immutable list of all mentionedRoles
.org.apache.commons.collections4.Bag<Role>
ABag
of mentioned roles.@Unmodifiable List<SlashCommandReference>
An immutable list of all mentionedslash commands
.org.apache.commons.collections4.Bag<SlashCommandReference>
ABag
of mentionedslash commands
.getUsers()
An immutable list of all mentionedUsers
.org.apache.commons.collections4.Bag<User>
ABag
of mentionedUsers
.boolean
isMentioned
(IMentionable mentionable, Message.MentionType... types) Checks if givenIMentionable
was mentioned in any way (@User, @everyone, @here, @Role).boolean
Indicates if everyone is mentioned, by either using@everyone
or@here
.
-
Method Details
-
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
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
ABag
of 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:
Bag
of 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
ABag
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
An immutable list of all mentionedGuildChannels
of typeclazz
.
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
- TheGuildChannel
sub-classclass object
of the type of channel desired- Returns:
- Immutable list of mentioned GuildChannels that are of type
clazz
. - Throws:
IllegalArgumentException
- Ifclazz
isnull
-
getChannelsBag
@Nonnull <T extends GuildChannel> org.apache.commons.collections4.Bag<T> getChannelsBag(@Nonnull Class<T> clazz) ABag
of mentioned channels of typeclazz
.
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
- TheGuildChannel
sub-classclass object
of the type of channel desired- Returns:
Bag
of mentioned channels of typeclazz
- Throws:
IllegalArgumentException
- Ifclazz
isnull
- 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
ABag
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
AllCustomEmojis
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
ABag
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
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
PrivateChannels
.- Returns:
- Immutable list of mentioned Members, or an empty list
-
getMembersBag
ABag
of 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:
Bag
of 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
ABag
of 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:
Bag
of mentioned slash commands- See Also:
-
getMentions
Combines all instances ofIMentionable
filtered by the specifiedMentionType
values.
If aMember
is 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
-MentionTypes
to include- Returns:
- Immutable list of filtered
IMentionable
instances - Throws:
IllegalArgumentException
- If provided withnull
-
isMentioned
Checks if givenIMentionable
was mentioned in any way (@User, @everyone, @here, @Role).
If no filteringMentionTypes
are specified, all types are used.MentionType.HERE
andMentionType.EVERYONE
will only be checked, if the givenIMentionable
is of typeUser
orMember
.
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
-