私はdiscord.jsでnode.jsを使用してサーバーのプライベートチャットボットを作成しています。elseをチェックせずに実行する場合
私はあなたが戦争している相手を定義するコマンドにこのコードを使用しています。
不和に私は、独自の「戦争を!」実行する場合、私はこのエラーを取得:
場合、他に何が起こっているもの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.");
}
}
を書く示唆しています。 'name'という配列が何番になるのだろうか? – adeneo
また、おそらく 'let name = ... 'になるはずです – adeneo
ええ、私はそれを間違って使っていました。ありがとう。 – 975miles