我使用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