Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get if a specific user is online?

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());
  }
 }
});
like image 287
Vas Dávid Valentin Avatar asked Feb 02 '26 19:02

Vas Dávid Valentin


1 Answers

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!`);
        };
    };
});
like image 153
Jakye Avatar answered Feb 04 '26 08:02

Jakye



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!