Package com.jagrosh.jdautilities.command
Class SlashCommandEvent
java.lang.Object
net.dv8tion.jda.api.events.Event
net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent
net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent
net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
com.jagrosh.jdautilities.command.SlashCommandEvent
- All Implemented Interfaces:
net.dv8tion.jda.api.entities.ISnowflake
,net.dv8tion.jda.api.events.GenericEvent
,net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback
,net.dv8tion.jda.api.interactions.callbacks.IModalCallback
,net.dv8tion.jda.api.interactions.callbacks.IReplyCallback
,net.dv8tion.jda.api.interactions.commands.CommandInteraction
,net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload
,net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction
,net.dv8tion.jda.api.interactions.Interaction
public class SlashCommandEvent
extends net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
A wrapper class for a
SlashCommandInteractionEvent
and CommandClient
.
From here, developers can invoke several useful and specialized methods to assist in Command function and development. Because this extends SlashCommandInteractionEvent, all methods from it work fine.
- Author:
- Olivia (Chew)
-
Field Summary
Fields inherited from class net.dv8tion.jda.api.events.Event
api, rawData, responseNumber
-
Constructor Summary
ConstructorDescriptionSlashCommandEvent
(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, CommandClient client) -
Method Summary
Modifier and TypeMethodDescriptionTheCommandClient
that this event was triggered from.net.dv8tion.jda.api.entities.channel.concrete.TextChannel
Gets theTextChannel
that this CommandEvent may have taken place on, ornull
if it didn't happen on a TextChannel.boolean
Will return if the provided key resolves into a provided Option for the SlashCommand.boolean
isFromType
(net.dv8tion.jda.api.entities.channel.ChannelType channelType) Compares a providedChannelType
with the one this event occurred on, returningtrue
if they are the same ChannelType.net.dv8tion.jda.api.entities.Message.Attachment
optAttachment
(String key) Gets the provided Option Key as an Attachment value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.Message.Attachment
optAttachment
(String key, net.dv8tion.jda.api.entities.Message.Attachment defaultValue) Gets the provided Option Key as an Attachment value, or returns the default one if the option cannot be found.boolean
optBoolean
(String key) Gets the provided Option Key as a boolean value, or returnsfalse
if the option cannot be found.boolean
optBoolean
(String key, boolean defaultValue) Gets the provided Option Key as a boolean value, or returns the default one if the option cannot be found.double
Gets the provided Option Key as a double value, or returns0.0
if the option cannot be found.double
Gets the provided Option Key as a double value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.channel.middleman.GuildChannel
optGuildChannel
(String key) Gets the provided Option Key as a GuildChannel value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.channel.middleman.GuildChannel
optGuildChannel
(String key, net.dv8tion.jda.api.entities.channel.middleman.GuildChannel defaultValue) Gets the provided Option Key as a GuildChannel value, or returns the default one if the option cannot be found.long
Gets the provided Option Key as a long value, or returns0
if the option cannot be found.long
Gets the provided Option Key as a long value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.Member
Gets the provided Option Key as a Member value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.Member
Gets the provided Option Key as a Member value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.IMentionable
optMentionable
(String key) Gets the provided Option Key as a IMentionable value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.IMentionable
optMentionable
(String key, net.dv8tion.jda.api.entities.IMentionable defaultValue) Gets the provided Option Key as a IMentionable value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.channel.middleman.MessageChannel
optMessageChannel
(String key) Gets the provided Option Key as a MessageChannel value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.channel.middleman.MessageChannel
optMessageChannel
(String key, net.dv8tion.jda.api.entities.channel.middleman.MessageChannel defaultValue) Gets the provided Option Key as a MessageChannel value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.Role
Gets the provided Option Key as a Role value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.Role
Gets the provided Option Key as a Role value, or returns the default one if the option cannot be found.Gets the provided Option Key as a String value, or returnsnull
if the option cannot be found.Gets the provided Option Key as a String value, or returns the default one if the option cannot be found.net.dv8tion.jda.api.entities.User
Gets the provided Option Key as a User value, or returnsnull
if the option cannot be found.net.dv8tion.jda.api.entities.User
Gets the provided Option Key as a User value, or returns the default one if the option cannot be found.Methods inherited from class net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent
getChannel, getInteraction
Methods inherited from class net.dv8tion.jda.api.events.interaction.command.GenericCommandInteractionEvent
deferReply, getCommandIdLong, getCommandType, getHook, getName, getOptions, getSubcommandGroup, getSubcommandName, isGuildCommand, replyModal
Methods inherited from class net.dv8tion.jda.api.events.interaction.GenericInteractionCreateEvent
getGuild, getGuildLocale, getIdLong, getMember, getToken, getTypeRaw, getUser, getUserLocale, isAcknowledged
Methods inherited from class net.dv8tion.jda.api.events.Event
getJDA, getRawData, getResponseNumber, toString
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.interactions.commands.CommandInteractionPayload
getCommandId, getCommandIdLong, getCommandString, getCommandType, getFullCommandName, getName, getOption, getOption, getOption, getOption, getOptions, getOptionsByName, getOptionsByType, getSubcommandGroup, getSubcommandName, isGlobalCommand, isGuildCommand
Methods inherited from interface net.dv8tion.jda.api.interactions.callbacks.IDeferrableCallback
getHook
Methods inherited from interface net.dv8tion.jda.api.interactions.callbacks.IModalCallback
replyModal
Methods inherited from interface net.dv8tion.jda.api.interactions.Interaction
getChannelType, getGuild, getGuildLocale, getJDA, getMember, getMessageChannel, getToken, getType, getTypeRaw, getUser, getUserLocale, isAcknowledged, isFromGuild
Methods inherited from interface net.dv8tion.jda.api.interactions.callbacks.IReplyCallback
deferReply, deferReply, reply, reply, replyComponents, replyComponents, replyEmbeds, replyEmbeds, replyFiles, replyFiles, replyFormat
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getIdLong, getTimeCreated
Methods inherited from interface net.dv8tion.jda.api.interactions.commands.SlashCommandInteraction
getGuildChannel
-
Constructor Details
-
SlashCommandEvent
public SlashCommandEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, CommandClient client)
-
-
Method Details
-
getClient
TheCommandClient
that this event was triggered from.- Returns:
- The CommandClient that this event was triggered from
-
optString
Gets the provided Option Key as a String value, or returnsnull
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optString
@Nullable @Contract("_, !null -> !null") public String optString(@NotNull String key, @Nullable String defaultValue) Gets the provided Option Key as a String value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optBoolean
Gets the provided Option Key as a boolean value, or returnsfalse
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or false if the option is not present
-
optBoolean
Gets the provided Option Key as a boolean value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- The fallback option in case of the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optLong
Gets the provided Option Key as a long value, or returns0
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or 0 if the option is not present
-
optLong
Gets the provided Option Key as a long value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- The fallback option in case of the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optDouble
Gets the provided Option Key as a double value, or returns0.0
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or 0.0 if the option is not present
-
optDouble
Gets the provided Option Key as a double value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- The fallback option in case of the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optGuildChannel
@Nullable public net.dv8tion.jda.api.entities.channel.middleman.GuildChannel optGuildChannel(@NotNull String key) Gets the provided Option Key as a GuildChannel value, or returnsnull
if the option cannot be found.
This will always return null when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optGuildChannel
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.channel.middleman.GuildChannel optGuildChannel(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.channel.middleman.GuildChannel defaultValue) Gets the provided Option Key as a GuildChannel value, or returns the default one if the option cannot be found.
This will always return the default value when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optMember
Gets the provided Option Key as a Member value, or returnsnull
if the option cannot be found.
This will always return null when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optMember
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.Member optMember(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.Member defaultValue) Gets the provided Option Key as a Member value, or returns the default one if the option cannot be found.
This will always return the default value when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optMentionable
Gets the provided Option Key as a IMentionable value, or returnsnull
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optMentionable
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.IMentionable optMentionable(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.IMentionable defaultValue) Gets the provided Option Key as a IMentionable value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optRole
Gets the provided Option Key as a Role value, or returnsnull
if the option cannot be found.
This will always return null when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optRole
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.Role optRole(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.Role defaultValue) Gets the provided Option Key as a Role value, or returns the default one if the option cannot be found.
This will always return the default value when the SlashCommandEvent was not executed in a Guild.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optUser
Gets the provided Option Key as a User value, or returnsnull
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optUser
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.User optUser(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.User defaultValue) Gets the provided Option Key as a User value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optMessageChannel
@Nullable public net.dv8tion.jda.api.entities.channel.middleman.MessageChannel optMessageChannel(@NotNull String key) Gets the provided Option Key as a MessageChannel value, or returnsnull
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or null if the option is not present
-
optMessageChannel
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.channel.middleman.MessageChannel optMessageChannel(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.channel.middleman.MessageChannel defaultValue) Gets the provided Option Key as a MessageChannel value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
optAttachment
Gets the provided Option Key as an Attachment value, or returnsnull
if the option cannot be found.- Parameters:
key
- The option we want- Returns:
- The provided option, or the default value if the option is not present
-
optAttachment
@Nullable @Contract("_, !null -> !null") public net.dv8tion.jda.api.entities.Message.Attachment optAttachment(@NotNull String key, @Nullable net.dv8tion.jda.api.entities.Message.Attachment defaultValue) Gets the provided Option Key as an Attachment value, or returns the default one if the option cannot be found.- Parameters:
key
- The option we wantdefaultValue
- Nullable default value used in the absence of the option value- Returns:
- The provided option, or the default value if the option is not present
-
hasOption
Will return if the provided key resolves into a provided Option for the SlashCommand.- Parameters:
key
- the option we want- Returns:
- true if the option exists, false otherwise
-
isFromType
public boolean isFromType(net.dv8tion.jda.api.entities.channel.ChannelType channelType) Compares a providedChannelType
with the one this event occurred on, returningtrue
if they are the same ChannelType.- Parameters:
channelType
- The ChannelType to compare- Returns:
true
if the CommandEvent originated from aMessageChannel
of the provided ChannelType, otherwisefalse
.
-
getTextChannel
public net.dv8tion.jda.api.entities.channel.concrete.TextChannel getTextChannel()Gets theTextChannel
that this CommandEvent may have taken place on, ornull
if it didn't happen on a TextChannel.- Returns:
- The TextChannel this CommandEvent may have taken place on, or null if it did not happen on a TextChannel.
-