Search code examples
javascriptnode.jstwitch

data.push is not working twitch bot


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)
    }
}

If i run the code twice, the first time the code in the else outside of the while (where it says //here) works however the second time the console outputs this : viewersWTP.push is not a function

Thanks in advance


Solution

  • What is viewersWTP = viewersWTP - 1 supposed to do? That's probably converting the array to NaN. Did you maybe mean WTPLength = WTPLength - 1?

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