mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
Make presences track users and guilds, emit them in presenceUpdate
This commit is contained in:
@@ -226,7 +226,7 @@ class Guild extends Base {
|
||||
|
||||
if (data.presences) {
|
||||
for (const presence of data.presences) {
|
||||
this.presences.add(presence);
|
||||
this.presences.add(Object.assign(presence, { guild: this }));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,7 @@ class GuildMember extends Base {
|
||||
* @readonly
|
||||
*/
|
||||
get presence() {
|
||||
return this.frozenPresence || this.guild.presences.get(this.id) || new Presence(this.client);
|
||||
return this.guild.presences.get(this.id) || new Presence(this.client);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -14,9 +14,27 @@ const { ActivityTypes, ActivityFlags } = require('../util/Constants');
|
||||
class Presence {
|
||||
constructor(client, data = {}) {
|
||||
Object.defineProperty(this, 'client', { value: client });
|
||||
this.userID = data.user.id;
|
||||
this.guild = data.guild;
|
||||
this.patch(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* The user of this presence
|
||||
* @type {User}
|
||||
*/
|
||||
get user() {
|
||||
return this.client.users.get(this.userID);
|
||||
}
|
||||
|
||||
/**
|
||||
* The member of this presence
|
||||
* @type {GuildMember}
|
||||
*/
|
||||
get member() {
|
||||
return this.guild.members.get(this.userID);
|
||||
}
|
||||
|
||||
patch(data) {
|
||||
/**
|
||||
* The status of the presence:
|
||||
|
||||
Reference in New Issue
Block a user