gpt4 book ai didi

javascript - 如何获取特定用户是否在线?

转载 作者:行者123 更新时间:2023-12-01 16:24:38 24 4
gpt4 key购买 nike

我有一些代码应该在用户切换到在线时发送用户的当前状态,但问题是它发送了两次消息而且我无法检查更改状态的用户是谁.我只想检查更改状态的用户是否是具有特定 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());
}
}
});

最佳答案

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!`);
};
};
});

关于javascript - 如何获取特定用户是否在线?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63860390/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com