mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-20 13:33:30 +01:00
Message patching: clear mention collections (#1138)
* Message patching: clear mention collections Fixes #1089 When discord sends an array of mentions, it is a full list of mentions -- therefore, we should clear the old mention collection. The same goes for when we re-analyze the message for channel mentions. * Use Collection.clear() instead of new Collection
This commit is contained in:
@@ -197,12 +197,13 @@ class Message {
|
|||||||
if (data.type === 6) this.system = true;
|
if (data.type === 6) this.system = true;
|
||||||
}
|
}
|
||||||
if (data.attachments) {
|
if (data.attachments) {
|
||||||
this.attachments = new Collection();
|
this.attachments.clear();
|
||||||
for (const attachment of data.attachments) {
|
for (const attachment of data.attachments) {
|
||||||
this.attachments.set(attachment.id, new Attachment(this, attachment));
|
this.attachments.set(attachment.id, new Attachment(this, attachment));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.mentions) {
|
if (data.mentions) {
|
||||||
|
this.mentions.users.clear();
|
||||||
for (const mention of data.mentions) {
|
for (const mention of data.mentions) {
|
||||||
let user = this.client.users.get(mention.id);
|
let user = this.client.users.get(mention.id);
|
||||||
if (user) {
|
if (user) {
|
||||||
@@ -214,6 +215,7 @@ class Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.mention_roles) {
|
if (data.mention_roles) {
|
||||||
|
this.mentions.roles.clear();
|
||||||
for (const mention of data.mention_roles) {
|
for (const mention of data.mention_roles) {
|
||||||
const role = this.channel.guild.roles.get(mention);
|
const role = this.channel.guild.roles.get(mention);
|
||||||
if (role) this.mentions.roles.set(role.id, role);
|
if (role) this.mentions.roles.set(role.id, role);
|
||||||
@@ -221,6 +223,7 @@ class Message {
|
|||||||
}
|
}
|
||||||
if (data.id) this.id = data.id;
|
if (data.id) this.id = data.id;
|
||||||
if (this.channel.guild && data.content) {
|
if (this.channel.guild && data.content) {
|
||||||
|
this.mentions.channels.clear();
|
||||||
const channMentionsRaw = data.content.match(/<#([0-9]{14,20})>/g) || [];
|
const channMentionsRaw = data.content.match(/<#([0-9]{14,20})>/g) || [];
|
||||||
for (const raw of channMentionsRaw) {
|
for (const raw of channMentionsRaw) {
|
||||||
const chan = this.channel.guild.channels.get(raw.match(/([0-9]{14,20})/g)[0]);
|
const chan = this.channel.guild.channels.get(raw.match(/([0-9]{14,20})/g)[0]);
|
||||||
@@ -228,7 +231,7 @@ class Message {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (data.reactions) {
|
if (data.reactions) {
|
||||||
this.reactions = new Collection();
|
this.reactions.clear();
|
||||||
if (data.reactions.length > 0) {
|
if (data.reactions.length > 0) {
|
||||||
for (const reaction of data.reactions) {
|
for (const reaction of data.reactions) {
|
||||||
const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name;
|
const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name;
|
||||||
|
|||||||
Reference in New Issue
Block a user