data.push不起作用twitch bot

时间:2018-06-19 17:17:23

标签: javascript node.js twitch

function lfg(user){
    WTPLength = viewersWTP.length;
    if (WTPLength !== 0) {
        viewersWTP = viewersWTP - 1
        while(WTPLength !== -1){
            if(user === viewersWTP[WTPLength]){
                console.log("Already in list")
                client.action("kong_plays",user+" you cannot execute this command again until kong pulls a viewer to play with him!")
                fil = True;
            }else{
                WTPLength = WTPLength - 1;
            }
        }if (fil !== true){
            viewersWTP.push(user);
            console.log("Added into list")
            client.action("kong_plays",viewersWTP)
        }
    }else{        //here
        viewersWTP.push(user);
            console.log(viewersWTP)
            client.action("kong_plays","1"+viewersWTP)
    }
}

如果我运行两次代码,则第一次在while以外的其他地方(这里表示//此处)运行代码,而第二次控制台输出以下代码:viewersWTP.push is not a function

预先感谢

1 个答案:

答案 0 :(得分:0)

viewersWTP = viewersWTP - 1应该做什么?那可能是将数组转换为NaN。您可能是说WTPLength = WTPLength - 1吗?

var a = [1, 2, 3];
console.log(a);
a = a - 1;
console.log(a);