我使用node.js和discord.js爲服務器創建私人聊天機器人。如果在沒有檢查的情況下運行,如果
我有一個命令的代碼來定義你與誰交戰。
我得到這個錯誤,如果不和諧我自身的運行「的戰爭!」:
TypeError: Cannot read property 'length' of undefined.
,如果發生了什麼事到別的嗎?
if (msg.content.startsWith(prefix + "war")) {
let [name] = msg.content.split(' ').slice(1);
if (name.length < 16) {
war[id[msg.author.id]] = name;
msg.channel.send("You are now at war with **" + name + "**. Use !pp for war info.");
console.log("Command executed : !war");
fs.writeFile('war.json', JSON.stringify(war));
} else if (name.isNaN) {
msg.channel.send("Enter something.");
} else {
msg.channel.send("Enter something with less than 16 characters.");
}
}
呃,'isNaN'通常是一個函數,稱爲像'isNaN(名稱)'。人們不知道一個數組,名稱是否曾經變成數字? – adeneo
另外,它應該可能是'let name = ...' – adeneo
是的,我錯誤地使用了它。謝謝。 – 975miles