#Cannot read properties of null (reading 'byteLength')

1 messages · Page 1 of 1 (latest)

stark fiber

I keep getting this error in my script but I can't figure out the cause of it.

TypeError: Cannot read properties of null (reading 'byteLength')
    at Object.pull (C:\Users\*\Documents\Bot\node_modules\undici\lib\web\fetch\body.js:66:20)
    at invokePromiseCallback (node:internal/webstreams/util:172:10)
    at Object.<anonymous> (node:internal/webstreams/util:177:23)
    at readableByteStreamControllerCallPullIfNeeded (node:internal/webstreams/readablestream:3145:24)
    at readableByteStreamControllerPullSteps (node:internal/webstreams/readablestream:3254:3)
    at [kPull] (node:internal/webstreams/readablestream:1201:5)
    at readableStreamDefaultReaderRead (node:internal/webstreams/readablestream:2269:39)
    at nextSteps (node:internal/webstreams/readablestream:493:7)
    at async writeIterable (C:\Users\*\Documents\Bot\node_modules\undici\lib\dispatcher\client-h1.js:1439:22)

Short code snippet:

if (interaction.commandName === "cardtest") {
    const canvas = createCanvas(700, 250);
    const context = canvas.getContext('2d');

    const backgroundPath = path.join(__dirname, "assets", "contribution-card-background.png")
    const background = await readFile(backgroundPath);
    const backgroundImage = new Image();
    backgroundImage.src = background;
    context.drawImage(backgroundImage, 0, 0, canvas.width, canvas.height);

    const attachment = new AttachmentBuilder(canvas.toBuffer('image/png'), { name: 'profile-image.png' });
    console.log(attachment)

    interaction.reply({ files: [attachment] });
}