I'm trying to build a bot that will send a message to a certain channel whenever a Twitch stream goes live. However, I've been having trouble with this array of streams that I have. I want the message to send ONCE when the stream comes online and then not send again until the stream has been marked as offline and comes online again. I can't for the life of me figure out why the below code won't do it.
var timer = setInterval(function(){
    var url = "https://api.twitch.tv/kraken/streams/";
    for(var i = 0; i < myStreams.length; i++){
        var currentStream = myStreams[i];   
        request({
        url: url + currentStream.urlsuffix,
        json: true
    }, function (error, response, body) {
        if(!error && response.statusCode === 200) {      
            if(body.stream != null){
                if(!currentStream.isOnline){
                    myBot.sendMessage(globalChannel, currentStream.name + " is going live! " + body["stream"]["channel"].url);  
                    currentStream.isOnline = true;
                    }
                }
            else{                           
                currentStream.isOnline = false;
                }
            }
        });
    }
}
// Change the 1 to how many seconds you want in between the requests for Twitch
, 1 * 1000);
I apologize in advance if my question is poorly formatted or if I've done anything wrong, this is my first time on Stack Overflow.
Thanks in advance!
EDIT: Fixed code syntax. The setInterval is needed to perform the request at a certain interval to Twitch because there is currently no streaming functionality for the Twitch API
