Class OptionMapping
java.lang.Object
net.dv8tion.jda.api.interactions.commands.OptionMapping
Name/Value pair for a
CommandInteraction option.
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 use getType() to do dynamic handling as well. Each getter documents the conditions and coercion rules for the specific types.
-
Constructor Summary
ConstructorsConstructorDescriptionOptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<Object> resolved, JDA jda, Guild guild) -
Method Summary
Modifier and TypeMethodDescriptionbooleanThe file uploaded for this option.booleanThe boolean value.The resolvedGuildChannelfor this option value.doubleThe double value for this option.intgetAsInt()The int value for this option.longThe long value for this option.The resolvedMemberfor this option value.The resolvedIMentionableinstance for this option value.The resolvedRolefor this option value.The String representation of this option value.The resolvedUserfor this option value.TheChannelTypefor the resolved channel.Resolved mentions for aSTRINGoption.getName()The name of this option.getType()TheOptionTypeof this option.inthashCode()toString()
-
Constructor Details
-
OptionMapping
public OptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<Object> resolved, JDA jda, Guild guild)
-
-
Method Details
-
getMentions
Resolved mentions for aSTRINGoption.
If this option is not of typeSTRING, this always returns empty lists. Mentions are sorted by occurrence.Mentioned
membersandrolesare always of the same guild. If the interactionuser, mentions users from other guilds, they will only be provided byMentions.getUsers().This is not supported for
CommandAutoCompleteInteraction.- Returns:
Mentionsfor this option
-
getType
TheOptionTypeof this option.- Returns:
- The
OptionType
-
getName
The name of this option.- Returns:
- The option name
-
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
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
The resolvedIMentionableinstance for this option value.- Returns:
- The resolved
IMentionable - Throws:
IllegalStateException- If the mentioned entity is not resolvable
-
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
The resolvedUserfor this option value.- Returns:
- The resolved
User - Throws:
IllegalStateException- If this option is not of typeUSERorMENTIONABLEwithout a resolved user
-
getAsRole
The resolvedRolefor this option value.- Returns:
- The resolved
Role - Throws:
IllegalStateException- If this option is not of typeROLEorMENTIONABLEwithout a resolved role
-
getChannelType
TheChannelTypefor the resolved channel.- Returns:
- The
ChannelType - Throws:
IllegalStateException- If this option is not of typeCHANNEL
-
getAsChannel
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
-
toString
-
hashCode
public int hashCode() -
equals
-