I’m working on a Discord bot that tracks online users, but I’m having trouble removing user IDs from my array when they go offline.
client.on("presenceUpdate", (previousPresence, currentPresence) => {
if(previousPresence.status !== currentPresence.status){
const userID = currentPresence.user.id;
if(currentPresence.status === "online"){
activeUsers.push(userID);
console.log("-------user online--------");
console.log(activeUsers);
}else
if(currentPresence.status === "offline"){
activeUsers.filter(id => id !== userID)
console.log("-------user offline--------");
console.log(activeUsers);
}
console.log(`${currentPresence.user.username} status changed to ${currentPresence.status}`);
}
});
The issue is that user IDs aren’t being removed from the array. Here’s what I see in the console:
-------user offline-------- []
-TestUser- is now offline
-------user online-------- [ '203287818330570752' ]
-TestUser- is now online
-------user offline-------- [ '203287818330570752' ]
-TestUser- is now offline
-------user online-------- [ '203287818330570752', '203287818330570752' ]
-TestUser- is now online
As you can see, the ID stays in the array and even gets duplicated. What am I doing wrong?