Interface Component

All Known Subinterfaces:
ActionComponent, ActionRow, ActionRowChildComponent, ActionRowChildComponentUnion, Button, Container, ContainerChildComponent, ContainerChildComponentUnion, EntitySelectMenu, FileDisplay, IComponentUnion, IDisableable, MediaGallery, MessageTopLevelComponent, MessageTopLevelComponentUnion, ModalTopLevelComponent, ModalTopLevelComponentUnion, Section, SectionAccessoryComponent, SectionAccessoryComponentUnion, SectionContentComponent, SectionContentComponentUnion, SelectMenu, Separator, StringSelectMenu, TextDisplay, TextInput, Thumbnail, UnknownComponent
All Known Implementing Classes:
ActionRowImpl, ButtonImpl, ContainerImpl, EntitySelectMenuImpl, FileDisplayFileUpload, FileDisplayImpl, MediaGalleryImpl, SectionImpl, SelectMenuImpl, SeparatorImpl, StringSelectMenuImpl, TextDisplayImpl, TextInputImpl, ThumbnailFileUpload, ThumbnailImpl, UnknownComponentImpl

public interface Component
Component of a Message or Modal.
These are used to extend messages with interactive elements such as buttons or select menus. Components are also the primary building blocks for Modals.

All components include a unique, positive, integer ID.
These identifiers can be set manually or automatically assigned by Discord, and are useful to identify any component.

Not every component can be used in Messages or Modals. Use Component.Type.isMessageCompatible() and Component.Type.isModalCompatible() to check whether a component can be used.

See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Interface
    Description
    static enum 
    The component types
  • Method Summary

    Modifier and Type
    Method
    Description
    The type of component.
    int
    The unique, numeric identifier of this component.
    default boolean
    Whether this Component is compatible with Messages.
    default boolean
    Whether this Component is compatible with Modals.
    withUniqueId(int uniqueId)
    Creates a new component with the provided numeric ID.
  • Method Details

    • getType

      The type of component.
      Returns:
      Component.Type
    • getUniqueId

      int getUniqueId()
      The unique, numeric identifier of this component.
      Can be set manually or automatically assigned by Discord (starting from 1). If it has not been assigned yet, this will return -1.

      Note: Older messages may return 0.

      Returns:
      The unique identifier of this component, or -1 if not assigned yet, or 0 on older messages
    • withUniqueId

      @Nonnull @CheckReturnValue Component withUniqueId(int uniqueId)
      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.
      Parameters:
      uniqueId - The new ID; must be higher or equal to 1
      Returns:
      The new component
      Throws:
      IllegalArgumentException - If the ID is less than 1
    • isMessageCompatible

      default boolean isMessageCompatible()
      Whether this Component is compatible with Messages.
      If the component in question contains other components, this also checks every component inside it.
      Returns:
      True, if this Component (and its children) is compatible with messages.
    • isModalCompatible

      default boolean isModalCompatible()
      Whether this Component is compatible with Modals.
      If the component in question contains other components, this also checks every component inside it.
      Returns:
      True, if this Component (and its children) is compatible with modals.