JavaScript
x
12
12
1
function onChatHandler(target, context, msg, self) {
2
if (self) { return; }
3
4
const xxs = ["asd","asdw"];
5
const commandName = msg.trim();
6
if (xxs.some(word => msg.content.toLowerCase().includes(word))) {
7
const num = rollDice();
8
client.say(target, `Gelen sayi ${num}`);
9
console.log(`* Bu ${commandName} komut kullanildi.`);
10
11
}
12
TypeError: Cannot read property ‘toLowerCase’ of undefined error
Advertisement
Answer
String.prototype.toLowerCase
is for a string. Value prototypes don’t work on an undefined
value (e.g: undefined.forEach
or undefined.keys
), nor do they work for values that don’t belong to that prototype of that value (e.g: "string".push
).
This error means that you are calling .toLowerCase
on a value that is undefined, so, using logic we can conclude that msg.content
is undefined.
To fix it, I recommend some debugging (try to console.log
msg if you can, and see what it contains).