I am making a Discord bot, and i want it to send a picture at a specific event (that is irrelevant). I'm facing a weird problem: whenever i try to use Canvas.createCanvas(x,y) my Node project exits without any error in logs (as im using it through batch, it just restarts and prints the 'ready' line). I think that the code is irrelevant here, because it just fails to do createCanvas.
I have tried adding console.log('line N') on each line with text, and from my testing it only comes to line 2. So line 3 (createCanvas) is not processed.
client.on('guildMemberAdd', async member => { //canvas IS defined earlier
const channel = 'channel id';
if (!channel) return;
const canvas = createCanvas(600, 600);
const ctx = canvas.getContext('2d');
const background = await loadImage('./images/welcome.png');
ctx.drawImage(background, 0, 0, canvas.width, canvas.height);
ctx.strokeStyle = '#676767';
ctx.strokeRect(0, 0, canvas.width, canvas.height);
ctx.beginPath();
ctx.arc(125, 125, 100, 0, Math.PI * 2, true);
ctx.closePath();
ctx.clip();
const { body: buffer } = await snekfetch.get(member.user.displayAvatarURL);
const avatar = await loadImage(buffer);
ctx.drawImage(avatar, 25, 25, 200, 200);
const attachment = new Discord.Attachment(canvas.toBuffer(), 'welcome-image.png');
channel.send(attachment);
});
I expect it to actually create the canvas and do the operations, but instead it just restarts the bot. Any help here?