Class OptionMapping
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.OptionMapping
-
public class OptionMapping extends Object
Name/Value pair for aCommandInteractionoption.Since values for command options are a union-type you can use this class to coerce the values to the desired target type.
You can usegetType()to do dynamic handling as well. Each getter documents the conditions and coercion rules for the specific types.
-
-
Constructor Summary
Constructors Constructor Description OptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<Object> resolved)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object obj)Message.AttachmentgetAsAttachment()The file uploaded for this option.AudioChannelgetAsAudioChannel()The resolvedAudioChannelfor this option value.booleangetAsBoolean()The boolean value.doublegetAsDouble()The double value for this option.GuildChannelgetAsGuildChannel()The resolvedGuildChannelfor this option value.intgetAsInt()The int value for this option.longgetAsLong()The long value for this option.MembergetAsMember()The resolvedMemberfor this option value.IMentionablegetAsMentionable()The resolvedIMentionableinstance for this option value.GuildMessageChannelgetAsMessageChannel()The resolvedGuildMessageChannelfor this option value.NewsChannelgetAsNewsChannel()The resolvedNewsChannelfor this option value.RolegetAsRole()The resolvedRolefor this option value.StageChannelgetAsStageChannel()The resolvedStageChannelfor this option value.StringgetAsString()The String representation of this option value.TextChannelgetAsTextChannel()The resolvedTextChannelfor this option value.ThreadChannelgetAsThreadChannel()The resolvedThreadChannelfor this option value.UsergetAsUser()The resolvedUserfor this option value.VoiceChannelgetAsVoiceChannel()The resolvedVoiceChannelfor this option value.ChannelTypegetChannelType()TheChannelTypefor the resolved channel.List<GuildChannel>getMentionedChannels()ResolvedGuildChannelmentions for aSTRINGoption.List<Member>getMentionedMembers()List<Role>getMentionedRoles()List<User>getMentionedUsers()List<IMentionable>getMentions()StringgetName()The name of this option.OptionTypegetType()TheOptionTypeof this option.inthashCode()StringtoString()
-
-
-
Constructor Detail
-
OptionMapping
public OptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<Object> resolved)
-
-
Method Detail
-
getMentionedMembers
@Nonnull public List<Member> getMentionedMembers()
ResolvedMembermentions for aSTRINGoption.
If this option is not of typeSTRING, this always returns an empty list. Mentions are sorted by occurrence.This only contains members of the guild. If the user mentions users from other guilds, they will only be provided by
getMentionedUsers().This is not supported for
CommandAutoCompleteInteraction.
-
getMentionedUsers
@Nonnull public List<User> getMentionedUsers()
ResolvedUsermentions for aSTRINGoption.
If this option is not of typeSTRING, this always returns an empty list. Mentions are sorted by occurrence.This may also contain users which are not members in the guild!
This is not supported for
CommandAutoCompleteInteraction.
-
getMentionedRoles
@Nonnull public List<Role> getMentionedRoles()
ResolvedRolementions for aSTRINGoption.
If this option is not of typeSTRING, this always returns an empty list. Mentions are sorted by occurrence.This is not supported for
CommandAutoCompleteInteraction.
-
getMentionedChannels
@Nonnull public List<GuildChannel> getMentionedChannels()
ResolvedGuildChannelmentions for aSTRINGoption.
If this option is not of typeSTRING, this always returns an empty list. Mentions are sorted by occurrence.This is not supported for
CommandAutoCompleteInteraction.- Returns:
ListofGuildChannelthe resolved guild channel mentions in a string option
-
getMentions
@Nonnull public List<IMentionable> getMentions()
All resolvedmentionsfor aSTRINGoption.
If this option is not of typeSTRING, this always returns an empty list. Mentions are sorted by occurrence.This is not supported for
CommandAutoCompleteInteraction. This mergesgetMentionedUsers(),getMentionedMembers(),getMentionedRoles(), andgetMentionedChannels().- Returns:
ListofIMentionablethe resolved mentions in a string option
-
getType
@Nonnull public OptionType getType()
TheOptionTypeof this option.- Returns:
- The
OptionType
-
getAsAttachment
@Nonnull public Message.Attachment getAsAttachment()
The file uploaded for this option.
This is represented as anephemeralattachment which will only be hosted for up to 2 weeks. If you want a permanent reference, you must download it.- Returns:
Attachment- Throws:
IllegalStateException- If this optiontypeis notOptionType.ATTACHMENT
-
getAsString
@Nonnull public String getAsString()
The String representation of this option value.
This will automatically convert the value to a string if the type is notOptionType.STRING.
This will be the ID of any resolved entity such asRoleorMember.- Returns:
- The String representation of this option value
-
getAsBoolean
public boolean getAsBoolean()
The boolean value.- Returns:
- The boolean value
- Throws:
IllegalStateException- If this option is not of typeBOOLEAN
-
getAsLong
public long getAsLong()
- Returns:
- The long value
- Throws:
IllegalStateException- If this optiontypecannot be converted to a longNumberFormatException- If this option is of typeSTRINGand could not be parsed to a valid long value
-
getAsInt
public int getAsInt()
The int value for this option.
This will be the ID of any resolved entity such asRoleorMember.It is highly recommended to assert int values by using
OptionData.setRequiredRange(long, long)- Returns:
- The int value
- Throws:
IllegalStateException- If this optiontypecannot be converted to a longNumberFormatException- If this option is of typeSTRINGand could not be parsed to a valid long valueArithmeticException- If the provided integer value cannot fit into a 32bit signed int
-
getAsDouble
public double getAsDouble()
The double value for this option.- Returns:
- The double value
- Throws:
IllegalStateException- If this optiontypecannot be converted to a doubleNumberFormatException- If this option is of typeSTRINGand could not be parsed to a valid double value
-
getAsMentionable
@Nonnull public IMentionable getAsMentionable()
The resolvedIMentionableinstance for this option value.- Returns:
- The resolved
IMentionable - Throws:
IllegalStateException- If the mentioned entity is not resolvable
-
getAsMember
@Nullable public Member getAsMember()
The resolvedMemberfor this option value.
Note thatOptionType.USERcan also accept users that are not members of a guild, in which case this will be null!- Returns:
- The resolved
Member, or null - Throws:
IllegalStateException- If this option is not of typeUSERorMENTIONABLE
-
getAsUser
@Nonnull public User getAsUser()
The resolvedUserfor this option value.- Returns:
- The resolved
User - Throws:
IllegalStateException- If this option is not of typeUSERorMENTIONABLEwithout a resolved user
-
getAsRole
@Nonnull public Role getAsRole()
The resolvedRolefor this option value.- Returns:
- The resolved
Role - Throws:
IllegalStateException- If this option is not of typeROLEorMENTIONABLEwithout a resolved role
-
getChannelType
@Nonnull public ChannelType getChannelType()
TheChannelTypefor the resolved channel.- Returns:
- The
ChannelType - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsGuildChannel
@Nonnull public GuildChannel getAsGuildChannel()
The resolvedGuildChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
GuildChannel - Throws:
IllegalStateException- If this option is not of typeCHANNELor could not be resolved for unexpected reasons
-
getAsMessageChannel
@Nullable public GuildMessageChannel getAsMessageChannel()
The resolvedGuildMessageChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
GuildMessageChannel, or null if this was not a message channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsTextChannel
@Nullable public TextChannel getAsTextChannel()
The resolvedTextChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
TextChannel, or null if this was not a text channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsNewsChannel
@Nullable public NewsChannel getAsNewsChannel()
The resolvedNewsChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
NewsChannel, or null if this was not a news channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsThreadChannel
@Nullable public ThreadChannel getAsThreadChannel()
The resolvedThreadChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
ThreadChannel, or null if this was not a thread channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsAudioChannel
@Nullable public AudioChannel getAsAudioChannel()
The resolvedAudioChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
AudioChannel, or null if this was not an audio channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsVoiceChannel
@Nullable public VoiceChannel getAsVoiceChannel()
The resolvedVoiceChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
VoiceChannel, or null if this was not a voice channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsStageChannel
@Nullable public StageChannel getAsStageChannel()
The resolvedStageChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
StageChannel, or null if this was not a stage channel - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
-