【问题标题】:How to get if a specific user is online?如何获取特定用户是否在线?
【发布时间】:2020-12-30 18:19:57
【问题描述】:

如果用户切换到在线状态,我有一些代码应该发送用户的当前状态,但问题是它发送了两次消息并且我无法检查更改状态的用户是谁.我只想检查更改状态的用户是否是具有特定 ID 的人,以及他们的状态是否更改为“在线”

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());
  }
 }
});

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:
    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!`);
            };
        };
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-04-13
      • 2015-09-13
      • 2020-05-05
      相关资源
      最近更新 更多