Class OptionData

    • Field Detail

      • MAX_POSITIVE_NUMBER

        public static final double MAX_POSITIVE_NUMBER
        The highest positive amount Discord allows the NUMBER type to be.
        See Also:
        Constant Field Values
      • MIN_NEGATIVE_NUMBER

        public static final double MIN_NEGATIVE_NUMBER
        The largest negative amount Discord allows the NUMBER type to be.
        See Also:
        Constant Field Values
      • MAX_NAME_LENGTH

        public static final int MAX_NAME_LENGTH
        The maximum length the name of an option can be.
        See Also:
        Constant Field Values
      • MAX_CHOICE_NAME_LENGTH

        public static final int MAX_CHOICE_NAME_LENGTH
        The maximum length of the name of Command Option Choice names
        See Also:
        Constant Field Values
      • MAX_DESCRIPTION_LENGTH

        public static final int MAX_DESCRIPTION_LENGTH
        The maximum length the description of an option can be.
        See Also:
        Constant Field Values
    • Constructor Detail

      • OptionData

        public OptionData​(@Nonnull
                          OptionType type,
                          @Nonnull
                          java.lang.String name,
                          @Nonnull
                          java.lang.String description)
        Create an option builder.
        This option is not required by default.
        Parameters:
        type - The OptionType
        name - The option name, up to 32 alphanumeric (with dash) lowercase characters, as defined by MAX_NAME_LENGTH
        description - The option description, up to 100 characters, as defined by MAX_DESCRIPTION_LENGTH
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
        • type is not null
        • name is alphanumeric (with dash), lowercase and between 1 and 32 characters long
        • description is between 1 and 100 characters long
      • OptionData

        public OptionData​(@Nonnull
                          OptionType type,
                          @Nonnull
                          java.lang.String name,
                          @Nonnull
                          java.lang.String description,
                          boolean isRequired)
        Create an option builder.
        Parameters:
        type - The OptionType
        name - The option name, up to 32 alphanumeric (with dash) lowercase characters, as defined by MAX_NAME_LENGTH
        description - The option description, up to 100 characters, as defined by MAX_DESCRIPTION_LENGTH
        isRequired - True, if this option is required
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
        • type is not null
        • name is alphanumeric (with dash), lowercase and between 1 and 32 characters long
        • description is between 1 and 100 characters long
    • Method Detail

      • getName

        @Nonnull
        public java.lang.String getName()
        The name for this option
        Returns:
        The name
      • getDescription

        @Nonnull
        public java.lang.String getDescription()
        The description for this option
        Returns:
        The description
      • isRequired

        public boolean isRequired()
        Whether this option is required.
        This can be configured with setRequired(boolean).

        Required options must always be set by the command invocation.

        Returns:
        True, if this option is required
      • getChannelTypes

        @Nonnull
        public java.util.EnumSet<ChannelType> getChannelTypes()
        The ChannelTypes this option is restricted to.
        This is empty if the option is not of type CHANNEL or not restricted to specific types.
        Returns:
        EnumSet of ChannelType
      • getMinValue

        @Nullable
        public java.lang.Number getMinValue()
        The minimum value which can be provided for this option.
        This returns null if the value is not set or if the option is not of type INTEGER or NUMBER.
        Returns:
        The minimum value for this option
      • getMaxValue

        @Nullable
        public java.lang.Number getMaxValue()
        The maximum value which can be provided for this option.
        This returns null if the value is not set or if the option is not of type INTEGER or NUMBER.
        Returns:
        The maximum value for this option
      • setName

        @Nonnull
        public OptionData setName​(@Nonnull
                                  java.lang.String name)
        Configure the name
        Parameters:
        name - The lowercase alphanumeric (with dash) name, 1-32 characters long
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If the name is null, empty, not alphanumeric, or not between 1-32 characters long, as defined by MAX_NAME_LENGTH
      • setDescription

        @Nonnull
        public OptionData setDescription​(@Nonnull
                                         java.lang.String description)
        Configure the description
        Parameters:
        description - The description, 1-100 characters, as defined by MAX_DESCRIPTION_LENGTH
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If the name is null or larger than MAX_DESCRIPTION_LENGTH
      • setRequired

        @Nonnull
        public OptionData setRequired​(boolean required)
        Configure whether the user must set this option.
        Required options must always be filled out when using the command.
        Parameters:
        required - True, if this option is required
        Returns:
        The OptionData instance, for chaining
      • setChannelTypes

        @Nonnull
        public OptionData setChannelTypes​(@Nonnull
                                          ChannelType... channelTypes)
        Configure the ChannelTypes to restrict this option to. This only applies to options of type CHANNEL.
        Parameters:
        channelTypes - The ChannelTypes to restrict this option to or empty array to accept all ChannelTypes
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setChannelTypes

        @Nonnull
        public OptionData setChannelTypes​(@Nonnull
                                          java.util.Collection<ChannelType> channelTypes)
        Configure the ChannelTypes to restrict this option to. This only applies to options of type CHANNEL.
        Parameters:
        channelTypes - The ChannelTypes to restrict this option to or empty collection to accept all ChannelTypes
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
        • type of this option is CHANNEL
        • channelTypes is not null
        • channelTypes doesn't contain null
        • channelTypes only contains guild channels
      • setMinValue

        @Nonnull
        public OptionData setMinValue​(long value)
        Configure the minimal value which can be provided for this option.
        Parameters:
        value - The minimal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setMinValue

        @Nonnull
        public OptionData setMinValue​(double value)
        Configure the minimal value which can be provided for this option.
        Parameters:
        value - The minimal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setMaxValue

        @Nonnull
        public OptionData setMaxValue​(long value)
        Configure the maximal value which can be provided for this option.
        Parameters:
        value - The maximal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setMaxValue

        @Nonnull
        public OptionData setMaxValue​(double value)
        Configure the maximal value which can be provided for this option.
        Parameters:
        value - The maximal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setRequiredRange

        @Nonnull
        public OptionData setRequiredRange​(long minValue,
                                           long maxValue)
        Configure the minimal and maximal value which can be provided for this option.
        Parameters:
        minValue - The minimal value which can be provided for this option.
        maxValue - The maximal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • setRequiredRange

        @Nonnull
        public OptionData setRequiredRange​(double minValue,
                                           double maxValue)
        Configure the minimal and maximal value which can be provided for this option.
        Parameters:
        minValue - The minimal value which can be provided for this option.
        maxValue - The maximal value which can be provided for this option.
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    java.lang.String name,
                                    double value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client, up to 100 characters long, as defined by MAX_CHOICE_NAME_LENGTH
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    java.lang.String name,
                                    int value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    java.lang.String name,
                                    long value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • addChoice

        @Nonnull
        public OptionData addChoice​(@Nonnull
                                    java.lang.String name,
                                    @Nonnull
                                    java.lang.String value)
        Add a predefined choice for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        name - The name used in the client
        value - The value received in OptionMapping
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
        • name is not null, empty and less or equal to 100 characters long
        • value is not null, empty and less or equal to 100 characters long
        • The amount of already set choices is less than MAX_CHOICES
        • The OptionType is OptionType.STRING
      • addChoices

        @Nonnull
        public OptionData addChoices​(@Nonnull
                                     Command.Choice... choices)
        Adds up to 25 predefined choices for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        choices - The choices to add
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • addChoices

        @Nonnull
        public OptionData addChoices​(@Nonnull
                                     java.util.Collection<? extends Command.Choice> choices)
        Adds up to 25 predefined choices for this option.
        The user can only provide one of the choices and cannot specify any other value.
        Parameters:
        choices - The choices to add
        Returns:
        The OptionData instance, for chaining
        Throws:
        java.lang.IllegalArgumentException - If any of the following checks fail
      • fromData

        @Nonnull
        public static OptionData fromData​(@Nonnull
                                          DataObject json)
        Parses the provided serialization back into an OptionData instance.
        This is the reverse function for toData().
        Parameters:
        json - The serialized DataObject representing the option
        Returns:
        The parsed OptionData instance, which can be further configured through setters
        Throws:
        ParsingException - If the serialized object is missing required fields
        java.lang.IllegalArgumentException - If any of the values are failing the respective checks such as length