Interface Checkbox

All Superinterfaces:
Component, ICustomId, LabelChildComponent

public interface Checkbox extends ICustomId, LabelChildComponent
A component displaying a box which can be checked. Useful for simple yes/no questions.

While you cannot set a checkbox as required, you can use a required CheckboxGroup with a single option instead!

Must be used inside Labels only!

See Also:
  • Field Details

    • CUSTOM_ID_MAX_LENGTH

      static final int CUSTOM_ID_MAX_LENGTH
      The maximum length a checkbox's custom ID. (100)
      See Also:
  • Method Details

    • withUniqueId

      @Nonnull @CheckReturnValue Checkbox withUniqueId(int uniqueId)
      Description copied from interface: Component
      Creates a new component with the provided numeric ID.
      If no ID is set, Discord will generate IDs incrementally starting from 1 and will not use existing IDs from the same message/modal.
      Specified by:
      withUniqueId in interface Component
      Specified by:
      withUniqueId in interface ICustomId
      Specified by:
      withUniqueId in interface LabelChildComponent
      Parameters:
      uniqueId - The new ID; must be higher or equal to 1
      Returns:
      The new component
    • withCustomId

      @Nonnull @CheckReturnValue Checkbox withCustomId(@Nonnull String customId)
      Creates a new instance with the provided custom ID.
      This is typically used to carry data between the modal creator and the modal handler.
      Parameters:
      customId - The custom ID to use
      Returns:
      The new, updated instance
      Throws:
      IllegalArgumentException - If the provided custom ID is null, blank, or longer than 100 characters
    • withDefault

      @Nonnull @CheckReturnValue Checkbox withDefault(boolean isDefault)
      Creates a new instance with the provided default selection state.

      Checkboxes are unchecked by default.

      Parameters:
      isDefault - The new default selection state
      Returns:
      The new, updated instance
    • getCustomId

      @Nonnull String getCustomId()
      Description copied from interface: ICustomId
      An unique component ID or null.
      Some components such as link buttons don't have this.

      Custom IDs can contain custom data, this is typically used to pass data between a slash command and your button listener.

      While this ID is unique and can be retrieved with ComponentInteraction.getComponentId(), you should use Component.getUniqueId() to identify a component in a single message, such as when replacing components using ComponentTree or IReplaceable.replace(ComponentReplacer).

      Specified by:
      getCustomId in interface ICustomId
      Returns:
      The component ID or null if not present
      See Also:
    • isDefault

      boolean isDefault()
      Whether this checkbox is selected by default.
      Returns:
      true if this is checked by default
    • of

      @Nonnull static Checkbox of(@Nonnull String customId)
      Creates a new checkbox with the provided custom ID, unselected by default.
      Parameters:
      customId - The custom ID
      Returns:
      The new instance
      Throws:
      IllegalArgumentException - If the provided custom ID is null, blank or longer than 100 characters
    • of

      @Nonnull static Checkbox of(@Nonnull String customId, boolean isDefault)
      Creates a new checkbox with the provided custom ID and selected state.
      Parameters:
      customId - The custom ID
      isDefault - Whether this checkbox will be selected by default
      Returns:
      The new instance
      Throws:
      IllegalArgumentException - If the provided custom ID is null, blank or longer than 100 characters