Interface MessageTopLevelComponentUnion

All Superinterfaces:
Component, IComponentUnion, MessageTopLevelComponent
All Known Implementing Classes:
ActionRowImpl, ContainerImpl, FileDisplayFileUpload, FileDisplayImpl, MediaGalleryImpl, SectionImpl, SeparatorImpl, TextDisplayImpl, UnknownComponentImpl

public interface MessageTopLevelComponentUnion extends MessageTopLevelComponent, IComponentUnion
  • Method Details

    • asActionRow

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

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

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

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

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

      
       //These are the same!
       Section section = union.asSection();
       Section section2 = (Section) union;
       
      You can use Component.getType() to see if the component is of type Component.Type.SECTION to validate whether you can call this method in addition to normal instanceof checks: component instanceof Section
      Returns:
      The component as a Section
      Throws:
      IllegalStateException - If the component represented by this union is not actually a Section.
    • 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.
    • asMediaGallery

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

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

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

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

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

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

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

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

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

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

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

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

      @Nonnull MessageTopLevelComponentUnion 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 MessageTopLevelComponent
      Parameters:
      uniqueId - The new ID; must be higher or equal to 1
      Returns:
      The new component