Package net.dv8tion.jda.api.entities
Class Message.Attachment
java.lang.Object
net.dv8tion.jda.api.entities.Message.Attachment
- All Implemented Interfaces:
Closeable
,AutoCloseable
,ISnowflake
,AttachedFile
- Enclosing interface:
- Message
Represents a
Message
file attachment.-
Field Summary
Fields inherited from interface net.dv8tion.jda.api.utils.AttachedFile
MAX_DESCRIPTION_LENGTH
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addPart
(okhttp3.MultipartBody.Builder builder, int index) Used internally to build the multipart request.void
close()
void
Forces the underlying resource to be closed, even if the file is already handled by a request.The Content-Type of this file.The description (alt text) of this attachment.double
Gets the duration of this attachment.The file extension of the Attachment when it was first uploaded.The file name of the Attachment when it was first uploaded.int
The height of the Attachment if this Attachment is an image/video.long
The Snowflake id of this entity.getJDA()
The corresponding JDA instance for this AttachmentgetProxy()
Returns anAttachmentProxy
for this attachment.Url to the resource proxied by the Discord CDN.int
getSize()
The size of the attachment in bytes.getUrl()
The url of the Attachment, most likely on the Discord servers.byte[]
Gets the waveform data encoded in this attachment.int
getWidth()
The width of the Attachment if this Attachment is an image/video.boolean
Whether or not this attachment is from an ephemeral Message.boolean
isImage()
Whether or not this attachment is an Image, based ongetWidth()
,getHeight()
, andgetFileExtension()
.boolean
Whether or not this attachment is marked as spoiler, based ongetFileName()
.boolean
isVideo()
Whether or not this attachment is a video, based ongetWidth()
,getHeight()
, andgetFileExtension()
.toAttachmentData
(int index) Used internally to build attachment descriptions for requests.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface net.dv8tion.jda.api.entities.ISnowflake
getId, getTimeCreated
-
Constructor Details
-
Attachment
-
-
Method Details
-
getJDA
The corresponding JDA instance for this Attachment- Returns:
- The corresponding JDA instance for this Attachment
-
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 interfaceISnowflake
- Returns:
- Long containing the Id.
-
getUrl
The url of the Attachment, most likely on the Discord servers.- Returns:
- Non-null String containing the Attachment URL.
-
getProxyUrl
Url to the resource proxied by the Discord CDN.- Returns:
- Non-null String containing the proxied Attachment url.
-
getProxy
Returns anAttachmentProxy
for this attachment.- Returns:
- Non-null
AttachmentProxy
of this attachment - See Also:
-
getFileName
The file name of the Attachment when it was first uploaded.- Returns:
- Non-null String containing the Attachment file name.
-
getFileExtension
The file extension of the Attachment when it was first uploaded.
Null is returned if no characters follow the last occurrence of the '.
' character (or if the character is not present ingetFileName()
).- Returns:
- Non-null String containing the Attachment file extension, or null if it can't be determined.
-
getContentType
The Content-Type of this file.
This is the Media type of the file that would be used in an HTTP request or similar.- Returns:
- The content-type, or null if this isn't provided
-
getDescription
The description (alt text) of this attachment.
This description is shown when hovering over the attachment in the client.- Returns:
- The description, or null if this isn't provided
-
getSize
public int getSize()The size of the attachment in bytes.
Example: ifgetSize()
returns 1024, then the attachment is 1024 bytes, or 1KiB, in size.- Returns:
- Positive int containing the size of the Attachment.
-
getHeight
public int getHeight()The height of the Attachment if this Attachment is an image/video.
If this Attachment is neither an image, nor a video, this returns -1.- Returns:
- int containing image/video Attachment height, or -1 if attachment is neither image nor video.
-
getWidth
public int getWidth()The width of the Attachment if this Attachment is an image/video.
If this Attachment is neither an image, nor a video, this returns -1.- Returns:
- int containing image/video Attachment width, or -1 if attachment is neither image nor video.
-
isEphemeral
public boolean isEphemeral()Whether or not this attachment is from an ephemeral Message.
If this Attachment is ephemeral, it will automatically be removed after 2 weeks. The attachment is guaranteed to be available as long as the message itself exists.- Returns:
- True if this attachment is from an ephemeral message
-
getWaveform
Gets the waveform data encoded in this attachment. This is currently only present onvoice messages
.- Returns:
- A possibly-
null
array of integers representing the amplitude of the audio over time. Amplitude is sampled at 10Hz, but the client will decrease this to keep the waveform to at most 256 bytes. The values in this array are unsigned.
-
getDuration
public double getDuration()Gets the duration of this attachment. This is currently only nonzero onvoice messages
.- Returns:
- The duration of this attachment's audio in seconds, or
0
if this is not a voice message.
-
isImage
public boolean isImage()Whether or not this attachment is an Image, based ongetWidth()
,getHeight()
, andgetFileExtension()
.- Returns:
- True if this attachment is an image
-
isVideo
public boolean isVideo()Whether or not this attachment is a video, based ongetWidth()
,getHeight()
, andgetFileExtension()
.- Returns:
- True if this attachment is a video
-
isSpoiler
public boolean isSpoiler()Whether or not this attachment is marked as spoiler, based ongetFileName()
.- Returns:
- True if this attachment is marked as spoiler
- Since:
- 4.2.1
-
close
public void close()- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
-
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 interfaceAttachedFile
-
addPart
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 interfaceAttachedFile
- Parameters:
builder
- TheMultipartBody.Builder
used for the request bodyindex
- The index of the attachment, ignored forAttachmentUpdate
-
toAttachmentData
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 interfaceAttachedFile
- Parameters:
index
- The reference index (should be same asAttachedFile.addPart(MultipartBody.Builder, int)
)- Returns:
DataObject
for the attachment
-