Class OptionMapping
- java.lang.Object
-
- net.dv8tion.jda.api.interactions.commands.OptionMapping
-
public class OptionMapping extends java.lang.Object
Name/Value pair for aCommandInteraction
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 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 boolean
equals(java.lang.Object obj)
boolean
getAsBoolean()
The boolean value.double
getAsDouble()
The double value for this option.GuildChannel
getAsGuildChannel()
The resolvedGuildChannel
for this option value.long
getAsLong()
The long value for this option.Member
getAsMember()
The resolvedMember
for this option value.IMentionable
getAsMentionable()
The resolvedIMentionable
instance for this option value.MessageChannel
getAsMessageChannel()
The resolvedMessageChannel
for this option value.Role
getAsRole()
The resolvedRole
for this option value.java.lang.String
getAsString()
The String representation of this option value.User
getAsUser()
The resolvedUser
for this option value.ChannelType
getChannelType()
TheChannelType
for the resolved channel.java.lang.String
getName()
The name of this option.OptionType
getType()
TheOptionType
of this option.int
hashCode()
java.lang.String
toString()
-
-
-
Constructor Detail
-
OptionMapping
public OptionMapping(DataObject data, gnu.trove.map.TLongObjectMap<java.lang.Object> resolved)
-
-
Method Detail
-
getType
@Nonnull public OptionType getType()
TheOptionType
of 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 asRole
orMember
.- 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 resolvedIMentionable
instance 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 resolvedMember
for this option value.
Note thatOptionType.USER
can also accept users that are not members of a guild, in which case this will be null!
-
getAsGuildChannel
@Nonnull public GuildChannel getAsGuildChannel()
The resolvedGuildChannel
for this option value.
Note thatOptionType.CHANNEL
can accept channels of any type!- Returns:
- The resolved
GuildChannel
- Throws:
java.lang.IllegalStateException
- If this option is not of typeCHANNEL
or could not be resolved for unexpected reasons
-
getAsMessageChannel
@Nullable public MessageChannel getAsMessageChannel()
The resolvedMessageChannel
for this option value.
Note thatOptionType.CHANNEL
can 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()
TheChannelType
for the resolved channel.- Returns:
- The
ChannelType
- Throws:
java.lang.IllegalStateException
- If this option is not of typeCHANNEL
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equals
in classjava.lang.Object
-
-