【发布时间】:2020-01-07 16:24:27
【问题描述】:
在 discord.js 中使用“presenceUpdate”事件时,当状态从“nothing”变为“streaming”时成功触发。但是,似乎如果我在触发事件后打开移动客户端,它会再次发生,并具有完全相同的“oldUser”和“newUser”。我正在使用 VSCode 并在本地运行我的 node.js 实例,因此我可以使用断点进行调试。
client.on("presenceUpdate", (oldUser, newUser) => {
//Exclude title changes and typing
if(oldUser.presence.game != null && oldUser.presence.game.streaming) {
return;
}
if(oldUser.displayName === "Test" && newUser.presence != null){
if(newUser.presence.game != null && newUser.presence.game.streaming){
client.channels.get("channelId").send("@everyone Test has started streaming!");
}
}
});
如您所见,我已经尝试使用第一个 if 块过滤这个“双重触发器”。这不成功,因为看起来第一次触发,新老用户和第二次触发完全一样。我能说的唯一区别是“clientStatus”现在包含“mobile: online”作为属性。有什么方法可以从代码方面首先防止这种双重触发,还是我需要对我的 if 语句进行更好的过滤?
【问题讨论】:
标签: javascript node.js discord discord.js