Bartosz
Bartosz

Reputation: 3

JDA doesn't support anymore attachments with downloadToFile()?

I write discord bot with using JDA and i have one important question how to download attachments or work with them? Because my IntelliJ say "Deprecated API usage" for method like attachment.downloadToFile("name.png); So now we shouldn't download users files send in message? Or how we should do it in good way? I search a lot of wiki from JDA and different posts, but everywhere i didn't see, a new option to handle this download files, becasue all methods to download, are "Deprecated API" even method like "attachment.retrieveInputStream().join()" retrieveInputStream its too not good way :(

Search a lot on wiki/others pages for more information but nothing found :(

Upvotes: 0

Views: 253

Answers (1)

Minn
Minn

Reputation: 6131

The deprecation notice says this:

Deprecated.

Replaced by getProxy(), see FileProxy.downloadToFile(File)

This means you should use attachment.getProxy().downloadToFile(File) instead.

Example:

attachment.getProxy().downloadToFile(new File("myimage.png")).thenAccept(file -> {
    System.out.println("Written to file " + file.getAbsolutePath() + ".");
});

Or using NIO instead:

attachment.getProxy().downloadToPath().thenAccept(path -> {
    System.out.println("Written to file " + path + ". Total size: " + Files.size(path));
});

Upvotes: 0

Related Questions