Discord JDA using a local image in an embed?

一笑奈何 提交于 2021-01-28 07:03:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!