是否可以使用Discord JDA将本地图像文件用作嵌入式消息中的缩略图/图像?
对于我的命令之一,我正在以编程方式构建图像并通过Imgur API上传,然后使用Imgur URL将其显示在嵌入式消息中。
我知道我可以将文件直接发送到频道,但我希望它包含在显示其他相关信息的嵌入文件中。
欢呼
答案 0 :(得分:1)
您可以按照documentation for setImage中的说明使用attachment://filename.ext
。
例如,如果您有一个名为cat-final-copy-final-LAST.png
的文件,则可以这样发送:
// 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();