fix(PresenceUpdate): Event not emit

This commit is contained in:
March 7th 2022-07-09 20:14:18 +07:00
parent 536a86a5f3
commit 2d78b2437e
4 changed files with 35 additions and 24 deletions

File diff suppressed because one or more lines are too long

View File

@ -1,6 +1,6 @@
{ {
"name": "discord.js-selfbot-v13", "name": "discord.js-selfbot-v13",
"version": "2.3.67", "version": "2.3.68",
"description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]", "description": "A unofficial discord.js fork for creating selfbots [Based on discord.js v13]",
"main": "./src/index.js", "main": "./src/index.js",
"types": "./typings/index.d.ts", "types": "./typings/index.d.ts",

View File

@ -13,9 +13,10 @@ 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);
} }
const guild = this.client.guilds.cache.get(data.guild_id); // Shet, user not received guild_id
if (!guild) return; 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 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') {
@ -27,7 +28,7 @@ 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 })); const newPresence = guild.presences._add(Object.assign(data, { guild }));
if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence)) { if (this.client.listenerCount(Events.PRESENCE_UPDATE) && !newPresence.equals(oldPresence) && !emited) {
/** /**
* Emitted whenever a guild member's presence (e.g. status, activity) is changed. * Emitted whenever a guild member's presence (e.g. status, activity) is changed.
* @event Client#presenceUpdate * @event Client#presenceUpdate
@ -35,6 +36,8 @@ class PresenceUpdateAction extends Action {
* @param {Presence} newPresence The presence after the update * @param {Presence} newPresence The presence after the update
*/ */
this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence); this.client.emit(Events.PRESENCE_UPDATE, oldPresence, newPresence);
emited = true;
}
} }
} }
} }

View File

@ -110,6 +110,14 @@ class Presence extends Base {
this.clientStatus ??= null; this.clientStatus ??= null;
} }
if ('last_modified' in data) {
/**
* The timestamp this presence was last updated
* @type {number}
*/
this.lastModified = data.last_modified;
}
return this; return this;
} }