Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I use a local image on a discord.js rich embed?

Tags:

discord.js

I have this code:

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

How can I use a local image path in place of a URL (on the .setImage() line)

like image 838
dperales555 Avatar asked Nov 30 '22 21:11

dperales555


2 Answers

Updated Luke's code to Discord.js v12 for anyone else in 2020 who has this same problem

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});
like image 174
zapper_max Avatar answered May 17 '23 08:05

zapper_max


In discord.js v13 and on, MessageEmbed#attachFiles has been deprecated. You should directly add the files into the response from now on.

MessageEmbed#attachFiles has been removed; files should now be attached directly to the message instead of the embed.

// Before v13
const embed = new Discord.MessageEmbed().setTitle('Attachments').attachFiles(['./image1.png', './image2.jpg']);
channel.send(embed);
// v13
const embed = new Discord.MessageEmbed().setTitle('Attachment').setImage('attachment://image.png');
channel.send({ embeds: [embed], files: ['./image.png'] });
like image 34
Nicholas Wong Avatar answered May 17 '23 08:05

Nicholas Wong