skip to Main Content

Lastest version of canvas, discord.js and node.js.

Here is the code:

    const attachment = new AttachmentBuilder(canvas.toBuffer("image/png"), {
      name: "DNI.png",
    });

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

  },

The console/terminal says: "AttachmentBuilder is not a constructor" when I use the / command.

2

Answers


  1. It looks like your forgot to import AttachmentBuilder frmom discord.js.

    const { AttachmentBuilder} = require("discord.js");
    
    //...
    
        const attachment = new AttachmentBuilder(canvas.toBuffer("image/png"), {
          name: "DNI.png",
        });
    
        await interaction.reply({ files: [attachment] })
    
      },
    
    Login or Signup to reply.
  2. Your attachment may already be an array, so there is no need to array it like embed.

    So your code should be

    await interaction.reply({ files: attachment })

    not

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

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search