Home > Mobile >  TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13
TypeError: Cannot read properties of undefined (reading 'path') in discord.js v13

Time:07-20

I was trying to send an attachment in discord.js v13 but I have this error, can someone help me please:

const rank = new canvacord.Rank()
    .setAvatar(member.user.displayAvatarURL({format: "jpg"}))
    .setUsername(member.user.username)
    .setCurrentXP(user.coinsInWallet)
    .setProgressBar("#57c478", "COLOR")
    .setUsername(member.user.username)
    .setDiscriminator(member.user.discriminator)

rank.build()
    .then(data => {
        const attachment = new Discord.MessageAttachment(data, "MoneyBotCard.png");
        message.channel.send({files: [{attachement: [attachment]}]})
    });

In this code, it throws an error:

node_modules/discord.js/src/structures/MessagePayload.js:240
      if (thing.path) {
                ^

TypeError: Cannot read properties of undefined (reading 'path')

I also tried to run this but it changed nothing:

npm install path

CodePudding user response:

First, it's a typo. There is an extra e in .send({files: [{attachement:. It should be .send({files: [{attachment:. But the value of attachment should not be an array either.

Anyway, you don't even need to use MessageAttachments. You can simply send the Buffer (data) like this:

rank
  .build()
  .then((data) => message.channel.send({ files: [{ attachment: data }] }));

enter image description here

  • Related