简体   繁体   中英

how do I use a downloaded image on a embed with discord.js V13

I want to remove the image link where it says ".setImage" and replace that with a downloaded image how would I go about that?

    /** @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] });
    }
});

You can use a imagehost like Imgur to upload your downloaded image and get the image url of it, and use that url in your .setImage() method, you can also use another imagehost, just use what u like:)

EDIT:

It's also possible to do it without a link or imagehost, here is an example:

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] });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM