【问题标题】:Discord JDA using a local image in an embed?Discord JDA 在嵌入中使用本地图像?
【发布时间】:2020-12-30 19:34:19
【问题描述】:

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

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

我知道我可以将文件直接发送到频道,但我希望它包含在显示其他相关信息的嵌入中。

干杯

【问题讨论】:

    标签: discord discord-jda


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 2021-02-01
      • 2021-03-17
      • 2022-11-23
      • 2020-05-13
      • 2021-08-11
      • 2021-02-02
      • 2021-11-26
      • 2020-11-28
      • 2018-12-14
      相关资源
      最近更新 更多