Class AttachmentUpdate

java.lang.Object
net.dv8tion.jda.api.utils.AttachmentUpdate
All Implemented Interfaces:
Closeable, AutoCloseable, ISnowflake, AttachedFile

public class AttachmentUpdate extends Object implements AttachedFile, ISnowflake
Represents existing message attachment.
This is primarily used for message edit requests, to specify which attachments to retain in the message after the update.
  • Method Details

    • fromAttachment

      @Nonnull public static AttachmentUpdate fromAttachment(long id)
      Creates an AttachmentUpdate with the given attachment id.
      This is primarily used for message edit requests, to specify which attachments to retain in the message after the update.
      Parameters:
      id - The id of the attachment to retain
      Returns:
      AttachmentUpdate
    • fromAttachment

      @Nonnull public static AttachmentUpdate fromAttachment(@Nonnull String id)
      Creates an AttachmentUpdate with the given attachment id.
      This is primarily used for message edit requests, to specify which attachments to retain in the message after the update.
      Parameters:
      id - The id of the attachment to retain
      Returns:
      AttachmentUpdate
      Throws:
      IllegalArgumentException - If the id is not a valid snowflake
    • fromAttachment

      @Nonnull public static AttachmentUpdate fromAttachment(@Nonnull Message.Attachment attachment)
      Creates an AttachmentUpdate with the given attachment.
      This is primarily used for message edit requests, to specify which attachments to retain in the message after the update.
      Parameters:
      attachment - The attachment to retain
      Returns:
      AttachmentUpdate
    • getName

      @Nullable public String getName()
      The existing attachment filename.
      Returns:
      The filename, or null if not provided
    • getIdLong

      public long getIdLong()
      Description copied from interface: ISnowflake
      The Snowflake id of this entity. This is unique to every entity and will never change.
      Specified by:
      getIdLong in interface ISnowflake
      Returns:
      Long containing the Id.
    • addPart

      public void addPart(@Nonnull okhttp3.MultipartBody.Builder builder, int index)
      Description copied from interface: AttachedFile
      Used internally to build the multipart request.

      The index can be used as a unique identifier for the multipart name, which is required to be unique by Discord.

      Specified by:
      addPart in interface AttachedFile
      Parameters:
      builder - The MultipartBody.Builder used for the request body
      index - The index of the attachment, ignored for AttachmentUpdate
    • toAttachmentData

      @Nonnull public DataObject toAttachmentData(int index)
      Description copied from interface: AttachedFile
      Used internally to build attachment descriptions for requests.
      This contains the id/index of the attachment, and the name of the file.
      Specified by:
      toAttachmentData in interface AttachedFile
      Parameters:
      index - The reference index (should be same as AttachedFile.addPart(MultipartBody.Builder, int))
      Returns:
      DataObject for the attachment
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • forceClose

      public void forceClose()
      Description copied from interface: AttachedFile
      Forces the underlying resource to be closed, even if the file is already handled by a request.
      Specified by:
      forceClose in interface AttachedFile
    • toString

      public String toString()
      Overrides:
      toString in class Object