Bot not sending Canvas - discord.js



我正在discord.js中做一个测试机器人,当调用$profile命令时,它会发送配置文件卡。但我对Canvas没有任何经验,所以我在谷歌上搜索了一些教程并遵循了

但问题是机器人不发送附件,我试过研究其他方法,但它们也不起作用

这是画布的代码

const Canvas = require('canvas')
const Discord = require("discord.js");
module.exports =
{
name: 'profile',
description: '',
run: async (client, message) =>
{
const profilecanvas = Canvas.createCanvas(660,315)
const ctx = profilecanvas.getContext('2d')
const bg = await Canvas.loadImage('https://i.imgur.com/______.png')
ctx.drawImage(bg, 0, 0, profilecanvas.width, profilecanvas.height);
ctx.strokeStyle = '#fdfd34';
ctx.strokeRect(0, 0, profilecanvas.width, profilecanvas.height);
const attachment = new Discord.MessageAttachment(profilecanvas.toBuffer(), bg);
message.channel.send('testing', attachment)
}
}

并且它发送";测试";通常,只有Canvas没有被发送,并且终端中没有出现语法错误

尝试传递MessageOptions类型参数,其中attachments属性的值是以attachment为唯一元素的数组,content属性的值为"测试":

message.channel.send({
attachments: [attachment],
content: "testing",
});

使用

message.channel.send({files: [attachment]});

如果你想在一条信息中包含图片和文字,那么

message.channel.send({
files: [attachment],
content: 'Message text'
});

最新更新