Interface SectionContentComponentUnion

All Superinterfaces:
Component, IComponentUnion, SectionContentComponent
All Known Implementing Classes:
TextDisplayImpl, UnknownComponentImpl

public interface SectionContentComponentUnion extends SectionContentComponent, IComponentUnion
Represents a union of SectionContentComponents that can be one of:
  • Method Details

    • asTextDisplay

      @Nonnull TextDisplay asTextDisplay()
      Casts this union to a TextDisplay. This method exists for developer discoverability.

      Note: This is effectively equivalent to using the cast operator:

      
       //These are the same!
       TextDisplay textDisplay = union.asTextDisplay();
       TextDisplay textDisplay2 = (TextDisplay) union;
       
      You can use Component.getType() to see if the component is of type Component.Type.TEXT_DISPLAY to validate whether you can call this method in addition to normal instanceof checks: component instanceof TextDisplay
      Returns:
      The component as a TextDisplay
      Throws:
      IllegalStateException - If the component represented by this union is not actually a TextDisplay.
    • withUniqueId

      @Nonnull SectionContentComponentUnion 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 IComponentUnion
      Specified by:
      withUniqueId in interface SectionContentComponent
      Parameters:
      uniqueId - The new ID; must be higher or equal to 1
      Returns:
      The new component