I used presence update for my Discord bot so when me or my friends are getting live on Twitch, the bot would send a message in a channel and console log. But when we go live, the bot does the job, like, it sends the first message then it starts spamming. As you may expect, I don't have the knowledge in js as I am a beginner. So, can someone tell me how to fix this problem or if it can be fixed? Here is my code:
if (!newPresence.activities) return false;
newPresence.activities.forEach(activity => {
if (activity.type == "STREAMING") {
console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
};
});
});
And here is the console.log spam:
Mini-Game#8953 is streaming at https://www.twitch.tv/murus.
Mini-Game#8953 is streaming at https://www.twitch.tv/murus.
Mini-Game#8953 is streaming at https://www.twitch.tv/murus.
Mini-Game#8953 is streaming at https://www.twitch.tv/murus.
CodePudding user response:
Add a return
after the console.log()
inside the forEach
newPresence.activities.forEach((activity,idx,arr) => {
if (activity.type == "STREAMING") {
console.log(`${newPresence.user.tag} is streaming at ${activity.url}.`);
return; //---> ADD this
};
});