问题
Is it possible to use a local image file as a thumbnail/image in an embedded message with Discord JDA?
For one of my commands i'm building an image programmatically and uploading it via the Imgur API before displaying it in an embedded message using the Imgur URL.
I know I can send the file to the channel directly but i'd like it to be contained within an embed that displays other relevant info.
Cheers
回答1:
You can use attachment://filename.ext
as described in the documentation for setImage.
For instance if you have a file called cat-final-copy-final-LAST.png
you can send it like this:
// the name locally is not cat.png but we can still call it cat.png when we send it with addFile
File file = new File("cat-final-copy-final-LAST.png");
EmbedBuilder embed = new EmbedBuilder();
// this URI "attachment://cat.png" references the attachment with the name "cat.png" that you pass in `addFile` below
embed.setImage("attachment://cat.png");
// this name does not have to be the same name the file has locally, it can be anything as long as the file extension is correct
channel.sendMessage(embed.build())
.addFile(file, "cat.png")
.queue();
来源:https://stackoverflow.com/questions/63861265/discord-jda-using-a-local-image-in-an-embed