Interface SlashCommandData

All Superinterfaces:
CommandData, SerializableData
All Known Subinterfaces:
CommandCreateAction

public interface SlashCommandData extends CommandData
Extension of CommandData which allows setting slash-command specific settings such as options and subcommands.
  • Method Details

    • setLocalizationFunction

      @Nonnull SlashCommandData setLocalizationFunction(@Nonnull LocalizationFunction localizationFunction)
      Description copied from interface: CommandData
      Sets the LocalizationFunction for this command
      This enables you to have the entirety of this command to be localized.
      Specified by:
      setLocalizationFunction in interface CommandData
      Parameters:
      localizationFunction - The localization function
      Returns:
      The builder instance, for chaining
    • setName

      @Nonnull SlashCommandData setName(@Nonnull String name)
      Description copied from interface: CommandData
      Configure the command name.
      Specified by:
      setName in interface CommandData
      Parameters:
      name - The name, 1-32 characters (lowercase and alphanumeric for Command.Type.SLASH)
      Returns:
      The builder instance, for chaining
    • setNameLocalization

      @Nonnull SlashCommandData setNameLocalization(@Nonnull DiscordLocale locale, @Nonnull String name)
      Description copied from interface: CommandData
      Sets a language-specific localization of this command's name.
      Specified by:
      setNameLocalization in interface CommandData
      Parameters:
      locale - The locale to associate the translated name with
      name - The translated name to put
      Returns:
      This builder instance, for chaining
    • setNameLocalizations

      @Nonnull SlashCommandData setNameLocalizations(@Nonnull Map<DiscordLocale, String> map)
      Description copied from interface: CommandData
      Sets multiple language-specific localizations of this command's name.
      Specified by:
      setNameLocalizations in interface CommandData
      Parameters:
      map - The map from which to transfer the translated names
      Returns:
      This builder instance, for chaining
    • setDefaultPermissions

      @Nonnull SlashCommandData setDefaultPermissions(@Nonnull DefaultMemberPermissions permission)
      Description copied from interface: CommandData
      Sets the Permissions that a user must have in a specific channel to be able to use this command.
      By default, everyone can use this command (DefaultMemberPermissions.ENABLED). Additionally, a command can be disabled for everyone but admins via DefaultMemberPermissions.DISABLED.

      These configurations can be overwritten by moderators in each guild. See Command.retrievePrivileges(net.dv8tion.jda.api.entities.Guild) to get moderator defined overrides.

      Specified by:
      setDefaultPermissions in interface CommandData
      Parameters:
      permission - DefaultMemberPermissions representing the default permissions of this command.
      Returns:
      The builder instance, for chaining
      See Also:
    • setContexts

      @Nonnull default SlashCommandData setContexts(@Nonnull InteractionContextType... contexts)
      Description copied from interface: CommandData
      Sets the contexts in which this command can be used (Default: Guild and Bot DMs).
      This only has an effect if this command is registered globally.
      Specified by:
      setContexts in interface CommandData
      Parameters:
      contexts - The contexts in which this command can be used
      Returns:
      The builder instance, for chaining
    • setContexts

      @Nonnull SlashCommandData setContexts(@Nonnull Collection<InteractionContextType> contexts)
      Description copied from interface: CommandData
      Sets the contexts in which this command can be used (Default: Guild and Bot DMs).
      This only has an effect if this command is registered globally.
      Specified by:
      setContexts in interface CommandData
      Parameters:
      contexts - The contexts in which this command can be used
      Returns:
      The builder instance, for chaining
    • setIntegrationTypes

      @Nonnull default SlashCommandData setIntegrationTypes(@Nonnull IntegrationType... integrationTypes)
      Description copied from interface: CommandData
      Sets the integration types on which this command can be installed on (Default: Guilds).
      This only has an effect if this command is registered globally.
      Specified by:
      setIntegrationTypes in interface CommandData
      Parameters:
      integrationTypes - The integration types on which this command can be installed on
      Returns:
      The builder instance, for chaining
    • setIntegrationTypes

      @Nonnull SlashCommandData setIntegrationTypes(@Nonnull Collection<IntegrationType> integrationTypes)
      Description copied from interface: CommandData
      Sets the integration types on which this command can be installed on (Default: Guilds).
      This only has an effect if this command is registered globally.
      Specified by:
      setIntegrationTypes in interface CommandData
      Parameters:
      integrationTypes - The integration types on which this command can be installed on
      Returns:
      The builder instance, for chaining
    • setNSFW

      @Nonnull SlashCommandData setNSFW(boolean nsfw)
      Description copied from interface: CommandData
      Sets whether this command should only be usable in NSFW (age-restricted) channels.
      Default: false

      Note: Age-restricted commands will not show up in direct messages by default unless the user enables them in their settings.

      Specified by:
      setNSFW in interface CommandData
      Parameters:
      nsfw - True, to make this command nsfw
      Returns:
      The builder instance, for chaining
      See Also:
    • setDescription

      @Nonnull SlashCommandData setDescription(@Nonnull String description)
      Configure the description
      Parameters:
      description - The description, 1-100 characters
      Returns:
      The builder, for chaining
      Throws:
      IllegalArgumentException - If the name is null or not between 1-100 characters
    • setDescriptionLocalization

      @Nonnull SlashCommandData setDescriptionLocalization(@Nonnull DiscordLocale locale, @Nonnull String description)
      Sets a language-specific localizations of this command's description.
      Parameters:
      locale - The locale to associate the translated description with
      description - The translated description to put
      Returns:
      This builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • setDescriptionLocalizations

      @Nonnull SlashCommandData setDescriptionLocalizations(@Nonnull Map<DiscordLocale, String> map)
      Sets multiple language-specific localizations of this command's description.
      Parameters:
      map - The map from which to transfer the translated descriptions
      Returns:
      This builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • getDescription

      @Nonnull String getDescription()
      The configured description
      Returns:
      The description
    • getDescriptionLocalizations

      @Nonnull LocalizationMap getDescriptionLocalizations()
      The localizations of this command's description for various languages.
      Returns:
      The LocalizationMap containing the mapping from DiscordLocale to the localized description
    • removeOptions

      boolean removeOptions(@Nonnull Predicate<? super OptionData> condition)
      Removes all options that evaluate to true under the provided condition.
      This will not affect options within subcommands. Use SubcommandData.removeOptions(Predicate) instead.

      Example: Remove all options

      command.removeOptions(option -> true);
      

      Example: Remove all options that are required

      command.removeOptions(option -> option.isRequired());
      
      Parameters:
      condition - The removal condition (must not throw)
      Returns:
      True, if any options were removed
      Throws:
      IllegalArgumentException - If the condition is null
    • removeOptionByName

      default boolean removeOptionByName(@Nonnull String name)
      Removes options by the provided name.
      This will not affect options within subcommands. Use SubcommandData.removeOptionByName(String) instead.
      Parameters:
      name - The case-sensitive option name
      Returns:
      True, if any options were removed
    • removeSubcommands

      boolean removeSubcommands(@Nonnull Predicate<? super SubcommandData> condition)
      Removes all subcommands that evaluate to true under the provided condition.
      This will not apply to subcommands within subcommand groups. Use SubcommandGroupData.removeSubcommand(Predicate) instead.

      Example: Remove all subcommands

      command.removeSubcommands(subcommand -> true);
      
      Parameters:
      condition - The removal condition (must not throw)
      Returns:
      True, if any subcommands were removed
      Throws:
      IllegalArgumentException - If the condition is null
    • removeSubcommandByName

      default boolean removeSubcommandByName(@Nonnull String name)
      Removes subcommands by the provided name.
      This will not apply to subcommands within subcommand groups. Use SubcommandGroupData.removeSubcommandByName(String) instead.
      Parameters:
      name - The case-sensitive subcommand name
      Returns:
      True, if any subcommands were removed
    • removeSubcommandGroups

      boolean removeSubcommandGroups(@Nonnull Predicate<? super SubcommandGroupData> condition)
      Removes all subcommand groups that evaluate to true under the provided condition.

      Example: Remove all subcommand groups

      command.removeSubcommandGroups(group -> true);
      
      Parameters:
      condition - The removal condition (must not throw)
      Returns:
      True, if any subcommand groups were removed
      Throws:
      IllegalArgumentException - If the condition is null
    • removeSubcommandGroupByName

      default boolean removeSubcommandGroupByName(@Nonnull String name)
      Removes subcommand groups by the provided name.
      Parameters:
      name - The case-sensitive subcommand group name
      Returns:
      True, if any subcommand groups were removed
    • getSubcommands

      @Nonnull @Unmodifiable List<SubcommandData> getSubcommands()
      The Subcommands in this command.
      Returns:
      Immutable list of SubcommandData
    • getSubcommandGroups

      @Nonnull @Unmodifiable List<SubcommandGroupData> getSubcommandGroups()
      The Subcommand Groups in this command.
      Returns:
      Immutable list of SubcommandGroupData
    • getOptions

      @Nonnull @Unmodifiable List<OptionData> getOptions()
      The options for this command.
      Returns:
      Immutable list of OptionData
    • addOptions

      @Nonnull SlashCommandData addOptions(@Nonnull OptionData... options)
      Adds up to 25 options to this command.

      Required options must be added before non-required options!

      Parameters:
      options - The Options to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • addOptions

      @Nonnull default SlashCommandData addOptions(@Nonnull Collection<? extends OptionData> options)
      Adds up to 25 options to this command.

      Required options must be added before non-required options!

      Parameters:
      options - The Options to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • addOption

      @Nonnull default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required, boolean autoComplete)
      Adds an option to this command.

      Required options must be added before non-required options!

      Parameters:
      type - The OptionType
      name - The lowercase option name, 1-32 characters
      description - The option description, 1-100 characters
      required - Whether this option is required (See OptionData.setRequired(boolean))
      autoComplete - Whether this option supports auto-complete via CommandAutoCompleteInteractionEvent, only supported for option types which support choices
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • addOption

      @Nonnull default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description, boolean required)
      Adds an option to this command.

      Required options must be added before non-required options!

      Parameters:
      type - The OptionType
      name - The lowercase option name, 1-32 characters
      description - The option description, 1-100 characters
      required - Whether this option is required (See OptionData.setRequired(boolean))
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • addOption

      @Nonnull default SlashCommandData addOption(@Nonnull OptionType type, @Nonnull String name, @Nonnull String description)
      Adds an option to this command.
      The option is set to be non-required! You can use addOption(OptionType, String, String, boolean) to add a required option instead.

      Required options must be added before non-required options!

      Parameters:
      type - The OptionType
      name - The lowercase option name, 1-32 characters
      description - The option description, 1-100 characters
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException -
    • addSubcommands

      @Nonnull SlashCommandData addSubcommands(@Nonnull SubcommandData... subcommands)
      Add up to 25 Subcommands to this command.
      When a subcommand or subcommand group is added, the base command itself cannot be used. Thus using addOptions(OptionData...) and addSubcommands(SubcommandData...) / addSubcommandGroups(SubcommandGroupData...) for the same command, is not supported.

      Valid command layouts are as follows:

      command
      |-- subcommand
      |__ subcommand group
          |__ subcommand
      
      command
      |__ subcommand group
          |__ subcommand
      
      command
      |-- option
      |__ option
      
      Having an option and subcommand simultaneously is not allowed.
      Parameters:
      subcommands - The subcommands to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException - If null, more than 25 subcommands, or duplicate subcommand names are provided. Also throws if you try adding subcommands when options are already present.
    • addSubcommands

      @Nonnull default SlashCommandData addSubcommands(@Nonnull Collection<? extends SubcommandData> subcommands)
      Add up to 25 Subcommands to this command.
      When a subcommand or subcommand group is added, the base command itself cannot be used. Thus using addOptions(OptionData...) and addSubcommands(SubcommandData...) / addSubcommandGroups(SubcommandGroupData...) for the same command, is not supported.

      Valid command layouts are as follows:

      command
      |-- subcommand
      |__ subcommand group
          |__ subcommand
      
      command
      |__ subcommand group
          |__ subcommand
      
      command
      |-- option
      |__ option
      
      Having an option and subcommand simultaneously is not allowed.
      Parameters:
      subcommands - The subcommands to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException - If null, more than 25 subcommands, or duplicate subcommand names are provided. Also throws if you try adding subcommands when options are already present.
    • addSubcommandGroups

      @Nonnull SlashCommandData addSubcommandGroups(@Nonnull SubcommandGroupData... groups)
      Add up to 25 Subcommand-Groups to this command.
      When a subcommand or subcommand group is added, the base command itself cannot be used. Thus using addOptions(OptionData...) and addSubcommands(SubcommandData...) / addSubcommandGroups(SubcommandGroupData...) for the same command, is not supported.

      Valid command layouts are as follows:

      command
      |-- subcommand
      |__ subcommand group
          |__ subcommand
      
      command
      |__ subcommand group
          |__ subcommand
      
      command
      |-- option
      |__ option
      
      Having an option and subcommand simultaneously is not allowed.
      Parameters:
      groups - The subcommand groups to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException - If null, more than 25 subcommand groups, or duplicate group names are provided. Also throws if you try adding subcommand groups when options are already present.
    • addSubcommandGroups

      @Nonnull default SlashCommandData addSubcommandGroups(@Nonnull Collection<? extends SubcommandGroupData> groups)
      Add up to 25 Subcommand-Groups to this command.
      When a subcommand or subcommand group is added, the base command itself cannot be used. Thus using addOptions(OptionData...) and addSubcommands(SubcommandData...) / addSubcommandGroups(SubcommandGroupData...) for the same command, is not supported.

      Valid command layouts are as follows:

      command
      |-- subcommand
      |__ subcommand group
          |__ subcommand
      
      command
      |__ subcommand group
          |__ subcommand
      
      command
      |-- option
      |__ option
      
      Having an option and subcommand simultaneously is not allowed.
      Parameters:
      groups - The subcommand groups to add
      Returns:
      The builder instance, for chaining
      Throws:
      IllegalArgumentException - If null, more than 25 subcommand groups, or duplicate group names are provided. Also throws if you try adding subcommand groups when options are already present.
    • fromCommand

      @Nonnull static SlashCommandData fromCommand(@Nonnull Command command)
      Converts the provided Command into a SlashCommandData instance.
      Parameters:
      command - The command to convert
      Returns:
      An instance of SlashCommandData
      Throws:
      IllegalArgumentException - If null is provided or the command has illegal configuration
    • fromData

      @Nonnull static SlashCommandData fromData(@Nonnull DataObject object)
      Parses the provided serialization back into a SlashCommandData instance.
      This is the reverse function for SerializableData.toData().
      Parameters:
      object - The serialized DataObject representing the command
      Returns:
      The parsed SlashCommandData instance, which can be further configured through setters
      Throws:
      ParsingException - If the serialized object is missing required fields
      IllegalArgumentException - If any of the values are failing the respective checks such as length
      See Also: