Search code examples
discorddiscord.js

Send Canvas in embed Discord.js


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

Solution

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

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