Update PresenceUpdate.js

This commit is contained in:
Elysia 2024-01-11 18:03:49 +07:00
parent 9af9d94908
commit 11d6cef551

View File

@ -13,11 +13,9 @@ class PresenceUpdateAction extends Action {
if (!user._equals(data.user)) this.client.actions.UserUpdate.handle(data.user);
}
// Shet, user not received guild_id
let emited = false;
for (const guild of this.client.guilds.cache.map(g => g)) {
if (!guild.members.cache.get(user.id)) continue;
const oldPresence = guild.presences.cache.get(user.id)?._clone() ?? null;
const guild = this.client.guilds.cache.get(data.guild_id);
if (guild) {
let member = guild.members.cache.get(user.id);
if (!member && data.status !== 'offline') {
member = guild.members._add({
@ -27,8 +25,13 @@ class PresenceUpdateAction extends Action {
});
this.client.emit(Events.GUILD_MEMBER_AVAILABLE, member);
}
const newPresence = guild.presences._add(Object.assign(data, { guild }));
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence) && !emited) {
}
const oldPresence = (guild || this.client).presences.cache.get(user.id)?._clone() ?? null;
const newPresence = (guild || this.client).presences._add(Object.assign(data, { guild }));
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence)) {
/**
* Emitted whenever a guild member's presence (e.g. status, activity) is changed.
* @event Client#presenceUpdate
@ -36,8 +39,6 @@ class PresenceUpdateAction extends Action {
* @param {Presence} newPresence The presence after the update
*/
this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
emited = true;
}
}
}
}