Hello, i am trying to attach an image in interaction.reply discord.js
I get this error : const { createCanvas, loadImage } = require('canvas');
code :
async function createCompositeImage(imageUrls) {
const canvasWidth = 700;
const canvasHeight = 250;
const canvas = createCanvas(canvasWidth, canvasHeight);
const ctx = canvas.getContext('2d');
// Set the background to transparent
ctx.fillStyle = 'rgba(0, 0, 0, 0)';
ctx.fillRect(0, 0, canvasWidth, canvasHeight);
const img = await loadImage(imageUrls[0]);
ctx.drawImage(img, 10, 100, 100, 100); // Adjust positioning and size as needed
// Draw the number
ctx.fillStyle = 'black';
ctx.font = '24px Arial';
ctx.fillText(`Filled Text`, 600, 200); // Adjust position as needed
// Convert canvas to base64 PNG data
const attachment = new AttachmentBuilder(await canvas.encode('png'), { name: 'list-image.png' });
return attachment;
}
await createCompositeImage(imageUrls)
.then(base64Image => {
listImage = base64Image;
})
.catch(err => {
console.error('Error occurred:', err);
cmdError = true;
});
if (cmdError == false && listImage != "") {
await interaction.deferReply();
const message = await interaction.editReply({
content: `Choose an item : `,
files: [listImage],
fetchReply: true,
});
}
Thank you