I’ve got some code which should send in the current status of a user if they switched to online, but the problem is that it sends the message twice AND that I can’t check who the user who changed their status is. I just want it to check IF the user who changed their status is a person with a specific ID and IF their status changed to “online”
bot.on('presenceUpdate', (oldMember, newMember) => { console.log(newMember.presence.status + ' ' + oldMember.presence.status); if (newMember.presence.status == 'online') { if (!(oldMember == newMember)) { bot.channels .get('622437397891907586') .send(newMember.presence.status.toString()); } } });
Advertisement
Answer
client.on("presenceUpdate", (oldGuildMember, newGuildMember) => { if (oldGuildMember.id !== "YOURID") return false; // Checking if the GuildMember is a specific user. if (oldGuildMember.presence.status !== newGuildMember.presence.status) { // Checking if the Presence is the same. if (newGuildMember.presence.status == "online") { // Checking if the GuildMember is online. const Channel = client.channels.get("CHANNELID"); if (!Channel) return console.error("Invalid channel."); if (newGuildMember.guild.id !== Channel.guild.id) return false; // Making sure the Message gets sent once. Channel.send(`${newGuildMember.user.tag} is now online!`); }; }; });