client.on('presenceUpdate', (oldPresence, newPresence) => {
if (!newPresence.activities) return false;
newPresence.activities.forEach(activity => {
if (activity.type == 'STREAMING') {
//Do stuff if someone starts a stream
}
I've been developing a Discord bot for my friend's Discord server which automatically notifies, if someone starts streaming. Everything was working fine and dandy, but then yesterday something that I cannot comprehend happened.
A person started streaming and the bot saw that, so it sent a message notifying people like it should. However, that same stream was nearing its end, when the bot decided "I'm gonne send 2 more notifications that the stream has started". These notifications were minute apart from each other.
Could someone please help me with this issue? I've provided a small code snippet from my code which checks if a person starts streaming. Is there a way to stop the bot from sending any more notifications if the user has been streaming? I'd only like the bot to notify about this once when someone starts streaming, not multiple times concerning one specific stream.
presenceUpdate would also emit, when someone goes into dnd or idle, as well as, when switching game.
So your case could be that the streamer either went idle and online, or switched application wich updated his activites and so their presence.
A possible fix would be to have a database ( or a temporary collection ) which tracks the active streamers so it only sends one message per stream and then waits until the stream is stopped.