Package org.javacord.api.entity
Interface Attachment
-
- All Superinterfaces:
DiscordEntity
- All Known Subinterfaces:
MessageAttachment
public interface Attachment extends DiscordEntity
This class represents an attachment.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description java.util.concurrent.CompletableFuture<byte[]>downloadAsByteArray()Gets the attachment as a byte array.java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage>downloadAsImage()Downloads the attachment as an image.java.io.InputStreamdownloadAsInputStream()Gets the attachment as an input stream.java.lang.StringgetFileName()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.URLgetProxyUrl()Gets the proxy url of the attachment.intgetSize()Gets the size of the attachment in bytes.java.net.URLgetUrl()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 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, getId, getIdAsString
-
-
-
-
Method Detail
-
getFileName
java.lang.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
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.
-
downloadAsInputStream
java.io.InputStream downloadAsInputStream() throws java.io.IOExceptionGets the attachment as an input stream.- Returns:
- The attachment as an input stream.
- Throws:
java.io.IOException- If an IO error occurs.
-
downloadAsByteArray
java.util.concurrent.CompletableFuture<byte[]> downloadAsByteArray()
Gets the attachment as a byte array.- Returns:
- The attachment as a byte array.
-
downloadAsImage
java.util.concurrent.CompletableFuture<java.awt.image.BufferedImage> downloadAsImage()
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.
-
-