mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 18:13:29 +01:00
feat(Message/Mentions): implement caching of members (#3684)
* Convert message#member to a getter * Try to cache members from data in message payloads * Cache mentioned members * Revert Message#member getter - breaking change * Revise member caching * Revise member mention caching * Pass member to _addMember correctly * Use message.guild instead of this.guild Co-Authored-By: SpaceEEC <spaceeec@yahoo.com> * Merge if's onto one line * fix(Message): use this.author.id to check cache Discord does not send an id in the member data here * chore(Message): reindent equals Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
This commit is contained in:
@@ -63,13 +63,6 @@ class Message {
|
|||||||
*/
|
*/
|
||||||
this.author = this.client.dataManager.newUser(data.author, !data.webhook_id);
|
this.author = this.client.dataManager.newUser(data.author, !data.webhook_id);
|
||||||
|
|
||||||
/**
|
|
||||||
* Represents the author of the message as a guild member
|
|
||||||
* Only available if the message comes from a guild where the author is still a member
|
|
||||||
* @type {?GuildMember}
|
|
||||||
*/
|
|
||||||
this.member = this.guild ? this.guild.member(this.author) || null : null;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Whether or not this message is pinned
|
* Whether or not this message is pinned
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
@@ -155,6 +148,17 @@ class Message {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
this._edits = [];
|
this._edits = [];
|
||||||
|
|
||||||
|
if (data.member && this.guild && this.author && !this.guild.members.has(this.author.id)) {
|
||||||
|
this.guild._addMember(Object.assign(data.member, { user: this.author }), false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents the author of the message as a guild member
|
||||||
|
* Only available if the message comes from a guild where the author is still a member
|
||||||
|
* @type {?GuildMember}
|
||||||
|
*/
|
||||||
|
this.member = this.guild ? this.guild.member(this.author) || null : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ class MessageMentions {
|
|||||||
let user = message.client.users.get(mention.id);
|
let user = message.client.users.get(mention.id);
|
||||||
if (!user) user = message.client.dataManager.newUser(mention);
|
if (!user) user = message.client.dataManager.newUser(mention);
|
||||||
this.users.set(user.id, user);
|
this.users.set(user.id, user);
|
||||||
|
if (mention.member && message.guild && !message.guild.members.has(mention.id)) {
|
||||||
|
message.guild._addMember(Object.assign(mention.member, { user }), false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Reference in New Issue
Block a user