1
votes

I'm trying to send the canvas image in an embed message, but doing it this way I only get it to send the photo and then the individual embed (I can't attach photos because of the poor reputation D :)

Sorry for the English, it is not my native language

    let channel = member.guild.channels.get('720372789286141963')
const Mensaje = {
    color: 1752220,
    title: `<a:pepeShoot:659762885706383380> | **Hola ${member.user.username}!**`,
    description: `**Bienvenid@ a:** \n Psyco RP`,
};

const file = {
    attachment: await createCanvas(),
    name:'bienvenida.jpg'
}
    
        channel.send({embed: Mensaje, files : [file]});
});
2

2 Answers

3
votes

Try buffering the image and then use .attachFiles(), like this:

const attachment = newDiscord.MessageAttachment(canvas.toBuffer(),'bufferedfilename.png'); 
 
const embed = new Discord.MessageEmbed()
    .attachFiles(attachment)
    .setImage('attachment://bufferedfilename.png');
2
votes

The easiest, and most highly recommended way to do this is to create a buffer of the image, since that can be directly placed into a setImage(). I also highly recommend using the embed constructor.

ctx.blahBlahBlah(); //make your image

const attachment = new Discord.Attachment(canvas.toBuffer(), 'image-name-here.png'); //buffer the canvas and pass it into an Attachment constructor

const myEmbed = new Discord.RichEmbed()
.setTitle(`<a:pepeShoot:659762885706383380> | **Hola ${member.user.username}!**`)
.setDescription(`**Bienvenid@ a:** \n Psyco RP`)
.setColor("1752220")
.setImage(attachment); //this is where we use the buffered image

message.channel.send(myEmbed);

It's pretty easy and intuitive, and I hope this helps!