Is this good practice?

I currently have a bot that checks every 2 minutes for speciffic twitch channels to be live, so it can send notifications to the respective channels.

I use setInterval to ‘ping’ the twitch API to check if any of the channels are live.

setInterval( function() { twitchHandler(client); }, interval );

the channels are stored in array for so I use a forEach to go trrough everyone and call the twitch API with twitch.js

The notifcation is sent and I flag it so it does not smap it
Of course I still ping the channel to check when it goes offline so i can refresh the notifications for the next time the streamer goes live

This feature is limited by 3 twtich channels per Guild, Since the bot is in 2 Guilds for now I think it is pretty ok.

Now the question as it states in the title. Is this good practice? or Is there another way to listen to specific stream user without using setInterval? Or am I doing ok and I’m just paranoid.

Would like to know a little feedback if I’m on the right track.

Thankyou!

Use EventSub instead

Then Twitch will tell you when a Stream goes live/offline.

But otherwise yeah this seems fine. It is one possible solution.

However I would group them into groups of 100, and lookup 100 streams at once, since the streams API lets you do 100 streams at once

See Example Request 3 https://dev.twitch.tv/docs/api/reference#get-streams

1 Like

That’s a solid answer! Thanks Barry. I guess I missed the EventSub in the documentation! Didn’t even know it was a thing.

Thanks a lot, I will check that out