Lokry
Lokry

Reputation: 73

.TypeError: Cannot read property 'content' of undefined

This is really confusing for me

Here is the error

TypeError: Cannot read property 'content' of undefined

And Here is the code

client.on("messageDelete", async (member, message) => {
      let aud = db.get(`auditchannel_${member.guild.id}`);
      if(aud === null) {
        return;
      }
      client.channels.cache.get(aud).send(`<@${member.member.user.id}>'s message was deleted in <#${member.channel.id}>`)
      console.log(message.content())
    })

Upvotes: 0

Views: 1249

Answers (2)

ryandi pratama purba
ryandi pratama purba

Reputation: 434

Undefined means that a variable has been declared but has not yet been assigned a value. This particular error is probably easiest to understand from the perspective of undefined, since undefined is not considered an object type at all (but its own undefined type instead), and properties can only belong to objects within JavaScript.

In the above code, when you get undefined error , you need to make sure that whichever variables throws undefined error, is assigned a value to it.

function myFunc(inVar) {
   if (inVar === undefined) {
        console.log(inVar.not)
  }
  return inVar;
}
var testVar=99;//initialize here
console.log(myFunc(testVar));

In the above JavaScript you can the variable testVar is initialized the value of 99. So the script run successfully.

Upvotes: 0

Jai248
Jai248

Reputation: 1649

messageDelete has only one argument see the example so message variable is undefined and you are trying to read 'content' of "message".

Upvotes: 1

Related Questions