#@napi-rs/canvas

2 messages · Page 1 of 1 (latest)

icy axle

Guys, why isn't the name appearing? Is there something wrong with the code below?

const canvasAvatar = Canvas.createCanvas(1000, 1000);
      const ctxAvatar = canvasAvatar.getContext("2d");

      const avatarBody = await request(message.author.displayAvatarURL({ extension: "jpg", size: 1024 }));
      const avatar = await Canvas.loadImage(await avatarBody.body.arrayBuffer());

      ctxAvatar.drawImage(avatar, 0, 0, 1000, 1000);

      const canvasWidth = 800;
      const canvasHeight = 240;

      const canvasBg1 = Canvas.createCanvas(canvasWidth, canvasHeight);
      const ctxBg1 = canvasBg1.getContext('2d');

      ctxBg1.globalAlpha = 0.2;
      ctxBg1.fillStyle = "#000000";
      ctxBg1.fillRect(0, 0, canvasWidth, canvasHeight);

      const canvas = Canvas.createCanvas(canvasWidth, canvasHeight);
      const ctx = canvas.getContext('2d');

      ctx.fillStyle = '#2c2f33';
      ctx.fillRect(0, 0, canvasWidth, canvasHeight);

      ctx.drawImage(canvasBg1, 20, 20, 760, 200);

      
      const name = message.author.username // formatText(message.author.username, 15)

      console.log(name)
      ctx.font = "50px sans-serif";
      ctx.fillStyle = "#ffffff";
      ctx.textAlign = "left";

      ctx.fillText(`${name}`, 400, 130);

      ctx.drawImage(canvasAvatar, 20, 20, 200, 200);

      const attachment = new AttachmentBuilder(await canvas.encode("png"), { name: 'xp-bar.png' });

      await message.channel.send({
         files: [attachment],
      });```
tender crestBOT
  • Consider reading #how-to-get-help to improve your question!
  • Explain what exactly your issue is.
  • Post the full error stack trace, not just the top part!
  • Show your code!
  • Issue solved? Press the button!
  • Marked as resolved by staff