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