Interface Attachment

    • Method Summary

      All Methods Instance Methods Abstract Methods Default Methods 
      Modifier and Type Method Description
      java.util.concurrent.CompletableFuture<byte[]> asByteArray()
      Downloads the attachment as a byte array.
      java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage> asImage()
      Downloads the attachment as an image.
      java.io.InputStream asInputStream()
      Downloads the attachment as an input stream.
      java.util.Optional<java.lang.String> getDescription()
      Gets the description of the attachment.
      java.lang.String getFileName()
      Gets the file name of the attachment.
      java.util.Optional<java.lang.Integer> getHeight()
      Gets the height of the attachment, if it's an image.
      java.net.URL getProxyUrl()
      Gets the proxy url of the attachment.
      int getSize()
      Gets the size of the attachment in bytes.
      java.net.URL getUrl()
      Gets the url of the attachment.
      java.util.Optional<java.lang.Integer> getWidth()
      Gets the width of the attachment, if it's an image.
      java.util.Optional<java.lang.Boolean> isEphemeral()
      Gets whether this attachment is ephemeral.
      default boolean isImage()
      Checks if the attachment is an image.
      default boolean isSpoiler()
      Checks whether the attachment is marked as a spoiler.
    • Method Detail

      • getFileName

        java.lang.String getFileName()
        Gets the file name of the attachment.
        Returns:
        The file name of the attachment.
      • getDescription

        java.util.Optional<java.lang.String> getDescription()
        Gets the description of the attachment.
        Returns:
        The description of the attachment.
      • getSize

        int getSize()
        Gets the size of the attachment in bytes.
        Returns:
        The size of the attachment in bytes.
      • getUrl

        java.net.URL getUrl()
        Gets the url of the attachment.
        Returns:
        The url of the attachment.
      • getProxyUrl

        java.net.URL getProxyUrl()
        Gets the proxy url of the attachment.
        Returns:
        The proxy url of the attachment.
      • isImage

        default boolean isImage()
        Checks if the attachment is an image.
        Returns:
        Whether the attachment is an image or not.
      • getHeight

        java.util.Optional<java.lang.Integer> getHeight()
        Gets the height of the attachment, if it's an image.
        Returns:
        The height of the attachment.
      • getWidth

        java.util.Optional<java.lang.Integer> getWidth()
        Gets the width of the attachment, if it's an image.
        Returns:
        The width of the attachment.
      • isEphemeral

        java.util.Optional<java.lang.Boolean> isEphemeral()
        Gets whether this attachment is ephemeral. Ephemeral attachments will automatically be removed after a set period of time and attachments on messages are guaranteed to be available as long as the message itself exists.
        Returns:
        True if the attachment is ephemeral.
      • asInputStream

        java.io.InputStream asInputStream()
                                   throws java.io.IOException
        Downloads the attachment as an input stream.
        Returns:
        The attachment as an input stream.
        Throws:
        java.io.IOException - If an IO error occurs.
      • asByteArray

        java.util.concurrent.CompletableFuture<byte[]> asByteArray()
        Downloads the attachment as a byte array.
        Returns:
        The attachment as a byte array.
      • asImage

        java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage> asImage()
        Downloads the attachment as an image.
        Returns:
        The attachment as an image. Only present, if the attachment is an image.
        Throws:
        java.lang.IllegalStateException - If the attachment is not an image.
      • isSpoiler

        default boolean isSpoiler()
        Checks whether the attachment is marked as a spoiler.

        Discord encodes the information on whether a file is considered a spoiler in the file name. Any file whose filename starts with SPOILER_ is considered a spoiler.

        Returns:
        The spoiler status.