Interface Checkbox
- All Superinterfaces:
Component, 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:
-
Nested Class Summary
Nested classes/interfaces inherited from interface Component
Component.Type -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe maximum length a checkbox's custom ID. -
Method Summary
Modifier and TypeMethodDescriptionAn unique component ID ornull.booleanWhether this checkbox is selected by default.static CheckboxCreates a new checkbox with the provided custom ID, unselected by default.static CheckboxCreates a new checkbox with the provided custom ID and selected state.withCustomId(String customId) Creates a new instance with the provided custom ID.withDefault(boolean isDefault) Creates a new instance with the provided default selection state.withUniqueId(int uniqueId) Creates a new component with the provided numeric ID.Methods inherited from interface Component
getType, getUniqueId, isMessageCompatible, isModalCompatible
-
Field Details
-
CUSTOM_ID_MAX_LENGTH
static final int CUSTOM_ID_MAX_LENGTHThe maximum length a checkbox's custom ID. (100)- See Also:
-
-
Method Details
-
withUniqueId
Description copied from interface:ComponentCreates 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:
withUniqueIdin interfaceComponent- Specified by:
withUniqueIdin interfaceICustomId- Specified by:
withUniqueIdin interfaceLabelChildComponent- Parameters:
uniqueId- The new ID; must be higher or equal to 1- Returns:
- The new component
-
withCustomId
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 isnull, blank, or longer than 100 characters
-
withDefault
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
Description copied from interface:ICustomIdAn unique component ID ornull.
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 useComponent.getUniqueId()to identify a component in a single message, such as when replacing components usingComponentTreeorIReplaceable.replace(ComponentReplacer).- Specified by:
getCustomIdin interfaceICustomId- Returns:
- The component ID or null if not present
- See Also:
-
isDefault
boolean isDefault()Whether this checkbox is selected by default.- Returns:
trueif this is checked by default
-
of
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 isnull, blank or longer than 100 characters
-
of
Creates a new checkbox with the provided custom ID and selected state.- Parameters:
customId- The custom IDisDefault- Whether this checkbox will be selected by default- Returns:
- The new instance
- Throws:
IllegalArgumentException- If the provided custom ID isnull, blank or longer than 100 characters
-