Interface FileDisplay

All Superinterfaces:
Component, ContainerChildComponent, MessageTopLevelComponent
All Known Implementing Classes:
FileDisplayFileUpload, FileDisplayImpl

public interface FileDisplay extends Component, MessageTopLevelComponent, ContainerChildComponent
Component displaying a file, you can mark it as a spoiler.

This will appear as a generic download-able file, meaning that audio files and text files cannot be played/previewed.
You can instead use media galleries to display images.

Requirements: Components V2 needs to be enabled!

  • Method Details

    • fromFile

      @Nonnull static FileDisplay fromFile(@Nonnull FileUpload file)
      Constructs a new FileDisplay from the FileUpload.

      This method can also be used to upload external resources, such as by using FileUpload.fromData(InputStream, String), in which case it will re-upload the entire file.

      This will automatically add the file when building the message, as such you do not need to add it manually (with MessageCreateRequest.addFiles(FileUpload...) for example).

      Example

      
       MessageChannel channel; // = reference of a MessageChannel
       // It's recommended to use a more robust HTTP library instead,
       // such as Java 11+'s HttpClient, or OkHttp (included with JDA), among many other options.
       InputStream file = new URL("https://http.cat/500").openStream();
       // You can also replace this with a local file
       FileDisplay fileDisplay = FileDisplay.fromFile(FileUpload.fromData(file, "cat.png"))
           .setDescription("This is a cute car :3");
       channel.sendComponents(fileDisplay)
           .useComponentsV2()
           .queue();
       
      Parameters:
      file - The FileUpload to display
      Returns:
      The new FileDisplay
      Throws:
      IllegalArgumentException - If null is provided
    • fromFileName

      @Nonnull static FileDisplay fromFileName(@Nonnull String fileName)
      Constructs a new FileDisplay with the provided file name.

      You will need to add the file before building the message, such as with MessageCreateRequest.addFiles(FileUpload...), for example.

      Example

      
       MessageChannel channel; // = reference of a MessageChannel
       // It's recommended to use a more robust HTTP library instead,
       // such as Java 11+'s HttpClient, or OkHttp (included with JDA), among many other options.
       InputStream file = new URL("https://http.cat/500").openStream();
       FileDisplay fileDisplay = FileDisplay.fromFileName("cat.png") // Match the file name in FileUpload
           .setDescription("This is a cute car :3");
       channel.sendComponents(fileDisplay)
           // You can also replace this with a local file
           .addFiles(FileUpload.fromData(file, "cat.png"))
           .useComponentsV2()
           .queue();
       
      Parameters:
      fileName - The name of the file to display
      Returns:
      The new FileDisplay
      Throws:
      IllegalArgumentException - If null is provided
    • withUniqueId

      @Nonnull @CheckReturnValue FileDisplay 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 ContainerChildComponent
      Specified by:
      withUniqueId in interface MessageTopLevelComponent
      Parameters:
      uniqueId - The new ID; must be higher or equal to 1
      Returns:
      The new component
    • withSpoiler

      @Nonnull @CheckReturnValue FileDisplay withSpoiler(boolean spoiler)
      Creates a new FileDisplay with the provided spoiler status.
      Spoilers are hidden until the user clicks on it.
      Parameters:
      spoiler - The new spoiler status
      Returns:
      The new FileDisplay
    • getUrl

      @Nonnull String getUrl()
      The URL of this file, this is always where the file originally came from.
      This can be either attachment://filename.extension or an actual URL.

      If you want to download the file, you should use getResolvedMedia() then ResolvedMedia.getProxy(), to avoid connecting your bot to unknown servers.

      Returns:
      The URL of this file
    • getResolvedMedia

      @Nullable ResolvedMedia getResolvedMedia()
      The media resolved from this file, this is only available if you receive this component from Discord.
      Returns:
      Possibly-null ResolvedMedia
    • isSpoiler

      boolean isSpoiler()
      Whether this file is hidden until the user clicks on it.
      Returns:
      true if this is hidden by default, false otherwise