Estoy haciendo un bot de prueba en discord.js que envía tarjetas de perfil cuando se llama al comando $profile. Pero no tengo experiencia con Canvas, así que busqué en Google algunos tutoriales y los seguí.
Pero el problema es que el bot no envía el archivo adjunto, he intentado investigar otras formas de hacerlo pero tampoco funcionan.
Este es el código del lienzo.
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) } }Y manda el "testing" normalmente, solo que el Canvas no se envía y no aparece error de sintaxis en el terminal
Intente pasar un parámetro de tipo MessageOptions , con una propiedad de attachments cuyo valor sea una matriz con su attachment como su único elemento, y una propiedad de content de valor "testing":
message.channel.send({ attachments: [attachment], content: "testing", });usar
message.channel.send({files: [attachment]});y si desea tener una imagen y texto en un mensaje, entonces
message.channel.send({ files: [attachment], content: 'Message text' });