【问题标题】:how do I use a downloaded image on a embed with discord.js V13如何在嵌入 discord.js V13 时使用下载的图像
【发布时间】:2021-10-28 13:41:18
【问题描述】:

我想删除显示“.setImage”的图片链接并将其替换为下载的图片我该怎么做?

    /** @format */
const Command = require("../Structures/Command.js");
const Discord = require("discord.js");
module.exports = new Command({
    name: "Cookie",
    description: "sends a image",
    permission: "SEND_MESSAGES", 
    async run(message, args, client) {
    const embed = new Discord.MessageEmbed();
        embed
            .setTitle("here is your cookie")
            .setDescription(
                "photo discription"
            )
            .setColor("BLURPLE")
            .setTimestamp()
            .setImage(
                "https://assets.bonappetit.com/photos/5ca534485e96521ff23b382b/1:1/w_2700,h_2700,c_limit/chocolate-chip-cookie.jpg"
            )
        message.reply({ embeds: [embed] });
    }
});

【问题讨论】:

标签: javascript discord.js


【解决方案1】:

您可以使用像Imgur 这样的图像主机来上传您下载的图像并获取它的图像网址,并在您的.setImage() 方法中使用该网址,您也可以使用另一个图像主机,只需使用您喜欢的 :)

编辑:

也可以在没有链接或镜像主机的情况下进行,这里是一个例子:

const image = new Discord.MessageAttachment('./path/to/image.png', 'attachement-name.png')

    const embed = new Discord.MessageEmbed();
        embed
            .setTitle("here is your cookie")
            .setDescription(
                "photo discription"
            )
            .setColor("BLURPLE")
            .setTimestamp()
            .setImage(
                "attachment://attachement-name.png"
            )
        message.reply({ embeds: [embed], files: [image] });

【讨论】:

  • 你应该展示一个如何做到这一点的代码示例。
  • 它只是将 url 作为字符串放入方法中,就像他对旧 url 所做的那样,代码示例是什么意思? ?
  • 展示如何以编程方式执行此操作。不要只说使用网站。展示如何连接和获取链接。
  • 每个人都知道如何使用 Imgur 我想,我不会浪费时间再一步一步地解释 Imgur,但如果你知道更好,请继续发布你自己的 :)
猜你喜欢
  • 2022-01-16
  • 2021-10-29
  • 1970-01-01
  • 2023-03-12
  • 2018-12-14
  • 2021-12-12
  • 1970-01-01
  • 2021-12-30
  • 2021-09-06
相关资源
最近更新 更多