Reputation: 73
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
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