如何在丰富的discord.js嵌入上使用本地图像?

时间:2018-07-05 21:09:29

标签: discord.js

我有此代码:

var datos = ["dato1","dato2","dato3"]

console.log ("》" + message.author.username + " introdujo el comando:  " + message.content + "  en  " + message.guild.name);

let embed = new discord.RichEmbed()
    .setTitle("Datos sobre gatos  ")

    .setColor(12118406)
    .setDescription(datos[Math.floor(Math.random() * datos.length)])
    .setFooter("© 2018 República Gamer LLC", bot.user.avatarURL)
    .setImage("http://i.imgur.com/sYyH2IM.png")
message.channel.send({embed})

.catch ((err) => {
    console.error(err);

    let embed = new discord.RichEmbed()
        .setColor(15806281)
        .setTitle("❌ Ocurrió un error")
        .setDescription("Ocurrió un error durante la ejecución del comando")
    message.channel.send({embed})
})

如何使用本地图像路径代替URL(在.setImage()行上)

4 个答案:

答案 0 :(得分:6)

在2020年将卢克(Luke)的代码更新为Discord.js v12,以解决其他有相同问题的人

const attachment = new Discord
                      .MessageAttachment('./card_images/sample.png', 'sample.png');
const embed = new Discord.MessageEmbed()
     .setTitle('Wicked Sweet Title')
     .attachFiles(attachment)
     .setImage('attachment://sample.png');

message.channel.send({embed});

答案 1 :(得分:1)

另一种方法是:

const attachment = new Discord.MessageAttachment('./help.png', 'help.png');


message.channel.send({
    embed: {
        files: [
            attachment
        ],
        image: {
            url: 'attachment://help.png'
        }
    }
});

答案 2 :(得分:0)

你好!不幸的是,Discord的API仅接受URL,而不接受本地路径。

您只能将图像上传到服务器/图像托管网站并获取URL。

答案 3 :(得分:0)

这对我有用。

const attachment = new Discord.Attachment('./card_images/sample.png', 'sample.png');
const embed = new RichEmbed()
        .setTitle('Wicked Sweet Title')
        .attachFile(attachment)
        .setImage('attachment://sample.png');
message.channel.send({embed}).catch(console.error)