Class OptionMapping
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.OptionMapping
-
public class OptionMapping extends java.lang.ObjectName/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<java.lang.Object> resolved)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object obj)booleangetAsBoolean()The boolean value.doublegetAsDouble()The double value for this option.GuildChannelgetAsGuildChannel()The resolvedGuildChannelfor this option value.longgetAsLong()The long value for this option.MembergetAsMember()The resolvedMemberfor this option value.IMentionablegetAsMentionable()The resolvedIMentionableinstance for this option value.MessageChannelgetAsMessageChannel()The resolvedMessageChannelfor this option value.RolegetAsRole()The resolvedRolefor this option value.java.lang.StringgetAsString()The String representation of this option value.UsergetAsUser()The resolvedUserfor this option value.ChannelTypegetChannelType()TheChannelTypefor the resolved channel.java.lang.StringgetName()The name of this option.OptionTypegetType()TheOptionTypeof this option.inthashCode()java.lang.StringtoString()
-
-
-
Constructor Detail
-
OptionMapping
public OptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<java.lang.Object> resolved)
-
-
Method Detail
-
getType
@Nonnull public OptionType getType()
TheOptionTypeof this option.- Returns:
- The
OptionType
-
getName
@Nonnull public java.lang.String getName()
The name of this option.- Returns:
- The option name
-
getAsString
@Nonnull public java.lang.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:
java.lang.IllegalStateException- If this option is not of typeBOOLEAN
-
getAsLong
public long getAsLong()
-
getAsDouble
public double getAsDouble()
The double value for this option.
-
getAsMentionable
@Nonnull public IMentionable getAsMentionable()
The resolvedIMentionableinstance for this option value.- Returns:
- The resolved
IMentionable - Throws:
java.lang.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!
-
getAsGuildChannel
@Nonnull public GuildChannel getAsGuildChannel()
The resolvedGuildChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
GuildChannel - Throws:
java.lang.IllegalStateException- If this option is not of typeCHANNELor could not be resolved for unexpected reasons
-
getAsMessageChannel
@Nullable public MessageChannel getAsMessageChannel()
The resolvedMessageChannelfor this option value.
Note thatOptionType.CHANNELcan accept channels of any type!- Returns:
- The resolved
MessageChannel, or null if this was not a message channel - Throws:
java.lang.IllegalStateException- If this option is not of typeCHANNEL
-
getChannelType
@Nonnull public ChannelType getChannelType()
TheChannelTypefor the resolved channel.- Returns:
- The
ChannelType - Throws:
java.lang.IllegalStateException- If this option is not of typeCHANNEL
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-