在嵌入Discord.js中发送画布

时间:2020-06-26 11:38:14

标签: discord discord.js

我正在尝试在嵌入消息中发送画布图像,但是这样做只能让我先发送照片,然后再进行个人嵌入(由于信誉D差,我无法附加照片:)

抱歉,英语不是我的母语

    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 个答案:

答案 0 :(得分:2)

尝试缓冲图像,然后使用.attachFiles(),如下所示:

const attachment = newDiscord.MessageAttachment(canvas.toBuffer(),'bufferedfilename.png'); 

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

答案 1 :(得分:1)

最简单,最推荐的方法是创建图像缓冲区,因为可以直接将其放入setImage()中。我也强烈建议使用embed构造函数。

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

这非常简单直观,我希望这会有所帮助!