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)
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});
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'] });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With