Discord JDA是否在嵌入中使用本地图像? [英] Discord JDA using a local image in an embed?

查看:62
本文介绍了Discord JDA是否在嵌入中使用本地图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以在Discord JDA中将本地图像文件用作嵌入式消息中的缩略图/图像?

Is it possible to use a local image file as a thumbnail/image in an embedded message with Discord JDA?

对于我的其中一个命令,我正在以编程方式构建图像并通过Imgur API上传图像,然后使用Imgur URL将其显示在嵌入式消息中.

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.

欢呼

推荐答案

您可以按照attachment://filename.ext .net/job/JDA/javadoc/net/dv8tion/jda/api/EmbedBuilder.html#setImage(java.lang.String)"rel =" nofollow noreferrer> setImage文档.

You can use attachment://filename.ext as described in the documentation for setImage.

例如,如果您有一个名为 cat-final-copy-final-LAST.png 的文件,则可以这样发送:

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();

这篇关于Discord JDA是否在嵌入中使用本地图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆