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

    Constructors
    Constructor
    Description
    SlashCommandEvent(net.dv8tion.jda.api.events.interaction.command.SlashCommandInteractionEvent event, CommandClient client)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    The CommandClient that this event was triggered from.
    net.dv8tion.jda.api.entities.channel.concrete.TextChannel
    Gets the TextChannel that this CommandEvent may have taken place on, or null 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 provided ChannelType with the one this event occurred on, returning true if they are the same ChannelType.
    net.dv8tion.jda.api.entities.Message.Attachment
    Gets the provided Option Key as an Attachment value, or returns null 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
    Gets the provided Option Key as a boolean value, or returns false 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 returns 0.0 if the option cannot be found.
    double
    optDouble(String key, double defaultValue)
    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
    Gets the provided Option Key as a GuildChannel value, or returns null 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 returns 0 if the option cannot be found.
    long
    optLong(String key, long defaultValue)
    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 returns null if the option cannot be found.
    net.dv8tion.jda.api.entities.Member
    optMember(String key, 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.
    net.dv8tion.jda.api.entities.IMentionable
    Gets the provided Option Key as a IMentionable value, or returns null 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
    Gets the provided Option Key as a MessageChannel value, or returns null 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 returns null if the option cannot be found.
    net.dv8tion.jda.api.entities.Role
    optRole(String key, 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.
    Gets the provided Option Key as a String value, or returns null if the option cannot be found.
    optString(String key, String defaultValue)
    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 returns null if the option cannot be found.
    net.dv8tion.jda.api.entities.User
    optUser(String key, 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.

    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

      public CommandClient getClient()
      The CommandClient that this event was triggered from.
      Returns:
      The CommandClient that this event was triggered from
    • optString

      @Nullable public String optString(@NotNull String key)
      Gets the provided Option Key as a String value, or returns null 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 want
      defaultValue - 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

      public boolean optBoolean(@NotNull String key)
      Gets the provided Option Key as a boolean value, or returns false 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

      public boolean optBoolean(@NotNull String key, boolean defaultValue)
      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 want
      defaultValue - 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

      public long optLong(@NotNull String key)
      Gets the provided Option Key as a long value, or returns 0 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

      public long optLong(@NotNull String key, long defaultValue)
      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 want
      defaultValue - 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

      public double optDouble(@NotNull String key)
      Gets the provided Option Key as a double value, or returns 0.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

      public double optDouble(@NotNull String key, double defaultValue)
      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 want
      defaultValue - 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 returns null 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 want
      defaultValue - 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

      @Nullable public net.dv8tion.jda.api.entities.Member optMember(@NotNull String key)
      Gets the provided Option Key as a Member value, or returns null 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 want
      defaultValue - 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

      @Nullable public net.dv8tion.jda.api.entities.IMentionable optMentionable(@NotNull String key)
      Gets the provided Option Key as a IMentionable value, or returns null 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 want
      defaultValue - 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

      @Nullable public net.dv8tion.jda.api.entities.Role optRole(@NotNull String key)
      Gets the provided Option Key as a Role value, or returns null 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 want
      defaultValue - 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

      @Nullable public net.dv8tion.jda.api.entities.User optUser(@NotNull String key)
      Gets the provided Option Key as a User value, or returns null 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 want
      defaultValue - 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 returns null 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 want
      defaultValue - 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

      @Nullable public net.dv8tion.jda.api.entities.Message.Attachment optAttachment(@NotNull String key)
      Gets the provided Option Key as an Attachment value, or returns null 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 want
      defaultValue - 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

      public boolean hasOption(@NotNull String key)
      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 provided ChannelType with the one this event occurred on, returning true if they are the same ChannelType.
      Parameters:
      channelType - The ChannelType to compare
      Returns:
      true if the CommandEvent originated from a MessageChannel of the provided ChannelType, otherwise false.
    • getTextChannel

      public net.dv8tion.jda.api.entities.channel.concrete.TextChannel getTextChannel()
      Gets the TextChannel that this CommandEvent may have taken place on, or null 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.