Package org.javacord.api.entity.message
Interface MessageAttachment
-
- All Superinterfaces:
DiscordEntity
public interface MessageAttachment extends DiscordEntity
This class represents a message attachment.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description CompletableFuture<byte[]>downloadAsByteArray()Gets the attachment as a byte array.CompletableFuture<BufferedImage>downloadAsImage()Downloads the attachment as an image.InputStreamdownloadAsInputStream()Gets the attachment as an input stream.StringgetFileName()Gets the file name of the attachment.Optional<Integer>getHeight()Gets the height of the attachment, if it's an image.MessagegetMessage()Gets the message of the attachment.URLgetProxyUrl()Gets the proxy url of the attachment.intgetSize()Gets the size of the attachment in bytes.URLgetUrl()Gets the url of the attachment.Optional<Integer>getWidth()Gets the width of the attachment, if it's an image.default booleanisImage()Checks if the attachment is an image.default booleanisSpoiler()Checks whether the attachment is marked as a spoiler.-
Methods inherited from interface org.javacord.api.entity.DiscordEntity
getApi, getCreationTimestamp, getCreationTimestamp, getId, getIdAsString
-
-
-
-
Method Detail
-
getMessage
Message getMessage()
Gets the message of the attachment.- Returns:
- The message of the attachment.
-
getFileName
String getFileName()
Gets the file name of the attachment.- Returns:
- The file name of the attachment.
-
getSize
int getSize()
Gets the size of the attachment in bytes.- Returns:
- The size of the attachment in bytes.
-
getUrl
URL getUrl()
Gets the url of the attachment.- Returns:
- The url of the attachment.
-
getProxyUrl
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
Optional<Integer> getHeight()
Gets the height of the attachment, if it's an image.- Returns:
- The height of the attachment.
-
getWidth
Optional<Integer> getWidth()
Gets the width of the attachment, if it's an image.- Returns:
- The width of the attachment.
-
downloadAsInputStream
InputStream downloadAsInputStream() throws IOException
Gets the attachment as an input stream.- Returns:
- The attachment as an input stream.
- Throws:
IOException- If an IO error occurs.
-
downloadAsByteArray
CompletableFuture<byte[]> downloadAsByteArray()
Gets the attachment as a byte array.- Returns:
- The attachment as a byte array.
-
downloadAsImage
CompletableFuture<BufferedImage> downloadAsImage()
Downloads the attachment as an image.- Returns:
- The attachment as an image. Only present, if the attachment is an image.
- Throws:
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.
-
-