TypeError:无法设置undefined的属性`3`

时间:2017-11-03 04:41:33

标签: javascript arrays undefined discord discord.js

var dogs = [1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0];
var loca = ['Trees', 'Rocks', 'L1', 'R1', 'L2', 'R2', 'L3', 'R3'];
var dog = dogs.map((v, i) => !v ? loca[i] : null).filter(v => v != null);
var Player3;
bot.on("message", function (msg) {
    if (msg.content === "!tree") { 
        Player3 = msg.author.id; msg.channel.send(`Registered Trees`); 
    }
    if (msg.author.id === Player3) {
        if (msg.content === "H") { dogs[3] = 0; msg.channel.send(`I need help at Trees!`); }
        if (msg.content === "D") { dogs[3] = 1; msg.channel.send(`Trees is dead!`); }
    }
    if (msg.content === "k") { 
        msg.channel.send(`Dogs still alive: ` + dog.join(", ")); 
    }  

在玩家3发送消息“H”之后,我需要程序以“Dogs still alive:Trees”回复 这是一个机器人,旨在协助在游乐园遭遇期间进行命运2袭击 目前,我遇到的问题是代码不会将dogs[3]的值更改为任何内容,因为它会响应以下错误:

C:\Users\maver\Document\TestBot\test1.js:136 (136 refers to line 9 here) 
        if (msg.content === "H") { dogs[3] = 0; msg.channel.send(`I need help at Trees!`); }
                                           ^
s
TypeError: Cannot set property `3` of undefined
    at Client.<anonymous> (C:\Users\maver\Document\TestBot\test1.js:136:45)

任何帮助都会受到影响。谢谢你的时间

0 个答案:

没有答案