Interface FileDisplay
- All Superinterfaces:
Component
,ContainerChildComponent
,MessageTopLevelComponent
- All Known Implementing Classes:
FileDisplayFileUpload
,FileDisplayImpl
This will appear as a generic download-able file,
meaning that audio files and text files cannot be played/previewed.
You can instead use media galleries to display images.
Requirements: Components V2 needs to be enabled!
-
Nested Class Summary
Nested classes/interfaces inherited from interface net.dv8tion.jda.api.components.Component
Component.Type
-
Method Summary
Modifier and TypeMethodDescriptionstatic FileDisplay
fromFile
(FileUpload file) Constructs a newFileDisplay
from theFileUpload
.static FileDisplay
fromFileName
(String fileName) Constructs a newFileDisplay
with the provided file name.The media resolved from this file, this is only available if you receive this component from Discord.getUrl()
The URL of this file, this is always where the file originally came from.boolean
Whether this file is hidden until the user clicks on it.withSpoiler
(boolean spoiler) Creates a newFileDisplay
with the provided spoiler status.withUniqueId
(int uniqueId) Creates a new component with the provided numeric ID.Methods inherited from interface net.dv8tion.jda.api.components.Component
getType, getUniqueId, isMessageCompatible, isModalCompatible
-
Method Details
-
fromFile
Constructs a newFileDisplay
from theFileUpload
.This method can also be used to upload external resources, such as by using
FileUpload.fromData(InputStream, String)
, in which case it will re-upload the entire file.This will automatically add the file when building the message, as such you do not need to add it manually (with
MessageCreateRequest.addFiles(FileUpload...)
for example).Example
MessageChannel channel; // = reference of a MessageChannel // It's recommended to use a more robust HTTP library instead, // such as Java 11+'s HttpClient, or OkHttp (included with JDA), among many other options. InputStream file = new URL("https://http.cat/500").openStream(); // You can also replace this with a local file FileDisplay fileDisplay = FileDisplay.fromFile(FileUpload.fromData(file, "cat.png")) .setDescription("This is a cute car :3"); channel.sendComponents(fileDisplay) .useComponentsV2() .queue();
- Parameters:
file
- TheFileUpload
to display- Returns:
- The new
FileDisplay
- Throws:
IllegalArgumentException
- Ifnull
is provided
-
fromFileName
Constructs a newFileDisplay
with the provided file name.You will need to add the file before building the message, such as with
MessageCreateRequest.addFiles(FileUpload...)
, for example.Example
MessageChannel channel; // = reference of a MessageChannel // It's recommended to use a more robust HTTP library instead, // such as Java 11+'s HttpClient, or OkHttp (included with JDA), among many other options. InputStream file = new URL("https://http.cat/500").openStream(); FileDisplay fileDisplay = FileDisplay.fromFileName("cat.png") // Match the file name in FileUpload .setDescription("This is a cute car :3"); channel.sendComponents(fileDisplay) // You can also replace this with a local file .addFiles(FileUpload.fromData(file, "cat.png")) .useComponentsV2() .queue();
- Parameters:
fileName
- The name of the file to display- Returns:
- The new
FileDisplay
- Throws:
IllegalArgumentException
- Ifnull
is provided
-
withUniqueId
Description copied from interface:Component
Creates a new component with the provided numeric ID.
If no ID is set, Discord will generate IDs incrementally starting from 1 and will not use existing IDs from the same message/modal.- Specified by:
withUniqueId
in interfaceComponent
- Specified by:
withUniqueId
in interfaceContainerChildComponent
- Specified by:
withUniqueId
in interfaceMessageTopLevelComponent
- Parameters:
uniqueId
- The new ID; must be higher or equal to 1- Returns:
- The new component
-
withSpoiler
Creates a newFileDisplay
with the provided spoiler status.
Spoilers are hidden until the user clicks on it.- Parameters:
spoiler
- The new spoiler status- Returns:
- The new
FileDisplay
-
getUrl
The URL of this file, this is always where the file originally came from.
This can be eitherattachment://filename.extension
or an actual URL.If you want to download the file, you should use
getResolvedMedia()
thenResolvedMedia.getProxy()
, to avoid connecting your bot to unknown servers.- Returns:
- The URL of this file
-
getResolvedMedia
The media resolved from this file, this is only available if you receive this component from Discord.- Returns:
- Possibly-null
ResolvedMedia
-
isSpoiler
boolean isSpoiler()Whether this file is hidden until the user clicks on it.- Returns:
true
if this is hidden by default,false
otherwise
-