Interface CommandInteraction
-
- All Superinterfaces:
Interaction
,ISnowflake
- All Known Implementing Classes:
SlashCommandEvent
public interface CommandInteraction extends Interaction
Interaction of a Slash-Command.- See Also:
SlashCommandEvent
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description MessageChannel
getChannel()
The channel this interaction happened in.default java.lang.String
getCommandId()
The command idlong
getCommandIdLong()
The command iddefault java.lang.String
getCommandPath()
default java.lang.String
getCommandString()
Gets the slash command String for this slash command.java.lang.String
getName()
The command name.default OptionMapping
getOption(java.lang.String name)
Finds the first option with the specified name.java.util.List<OptionMapping>
getOptions()
The options provided by the user when this command was executed.default java.util.List<OptionMapping>
getOptionsByName(java.lang.String name)
Gets all options for the specified name.default java.util.List<OptionMapping>
getOptionsByType(OptionType type)
Gets all options for the specified type.java.lang.String
getSubcommandGroup()
The subcommand group name.java.lang.String
getSubcommandName()
The subcommand name.-
Methods inherited from interface net.dv8tion.jda.api.interactions.Interaction
deferReply, deferReply, getChannelType, getGuild, getGuildChannel, getHook, getJDA, getMember, getMessageChannel, getPrivateChannel, getTextChannel, getToken, getType, getTypeRaw, getUser, getVoiceChannel, isAcknowledged, isFromGuild, reply, reply, replyEmbeds, replyEmbeds, replyFormat
-
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
-
-
-
-
Method Detail
-
getName
@Nonnull java.lang.String getName()
The command name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName
/name subcommandName
/name
getCommandPath()
to simplify your checks.- Returns:
- The command name
-
getSubcommandName
@Nullable java.lang.String getSubcommandName()
The subcommand name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName
/name subcommandName
/name
getCommandPath()
to simplify your checks.- Returns:
- The subcommand name, or null if this is not a subcommand
-
getSubcommandGroup
@Nullable java.lang.String getSubcommandGroup()
The subcommand group name.
This can be useful for abstractions.Note that commands can have these following structures:
/name subcommandGroup subcommandName
/name subcommandName
/name
getCommandPath()
to simplify your checks.- Returns:
- The subcommand group name, or null if this is not a subcommand group
-
getCommandPath
@Nonnull default java.lang.String getCommandPath()
Combination ofgetName()
,getSubcommandGroup()
, andgetSubcommandName()
.
This will format the command into a path such asmod/mute
wheremod
would be thegetName()
andmute
thegetSubcommandName()
.Examples:
/mod ban -> "mod/ban"
/admin config owner -> "admin/config/owner"
/ban -> "ban"
- Returns:
- The command path
-
getChannel
@Nonnull MessageChannel getChannel()
Description copied from interface:Interaction
The channel this interaction happened in.
This is currently never null, but might be nullable in the future.- Specified by:
getChannel
in interfaceInteraction
- Returns:
- The channel or null if this interaction is not from a channel context
-
getCommandIdLong
long getCommandIdLong()
The command id- Returns:
- The command id
-
getCommandId
@Nonnull default java.lang.String getCommandId()
The command id- Returns:
- The command id
-
getOptions
@Nonnull java.util.List<OptionMapping> getOptions()
The options provided by the user when this command was executed.
Each option has a name and value.- Returns:
- The options passed for this command
-
getOptionsByName
@Nonnull default java.util.List<OptionMapping> getOptionsByName(@Nonnull java.lang.String name)
Gets all options for the specified name.- Parameters:
name
- The option name- Returns:
- The list of options
- Throws:
java.lang.IllegalArgumentException
- If the provided name is null- See Also:
getOption(String)
-
getOptionsByType
@Nonnull default java.util.List<OptionMapping> getOptionsByType(@Nonnull OptionType type)
Gets all options for the specified type.- Parameters:
type
- The option type- Returns:
- The list of options
- Throws:
java.lang.IllegalArgumentException
- If the provided type is null
-
getOption
@Nullable default OptionMapping getOption(@Nonnull java.lang.String name)
Finds the first option with the specified name.- Parameters:
name
- The option name- Returns:
- The option with the provided name, or null if that option is not provided
- Throws:
java.lang.IllegalArgumentException
- If the name is null
-
getCommandString
@Nonnull default java.lang.String getCommandString()
Gets the slash command String for this slash command.
This is similar to the String you see when clicking the interaction name in the client.Example return for an echo command:
/say echo phrase: Say this
- Returns:
- The command String for this slash command
-
-