mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
fix(MessageReaction): fetching a removed partial custom emoji (#3955)
* fix: handling GuildEmoji within fetch() * refactor: remove unused "private" methods * refactor: make use of Message#fetch() to patch
This commit is contained in:
@@ -64,32 +64,6 @@ class ReactionManager extends BaseManager {
|
|||||||
.reactions.delete()
|
.reactions.delete()
|
||||||
.then(() => this.message);
|
.then(() => this.message);
|
||||||
}
|
}
|
||||||
|
|
||||||
_partial(emoji) {
|
|
||||||
const id = emoji.id || emoji.name;
|
|
||||||
const existing = this.cache.get(id);
|
|
||||||
return !existing || existing.partial;
|
|
||||||
}
|
|
||||||
|
|
||||||
async _fetchReaction(reactionEmoji, cache) {
|
|
||||||
const id = reactionEmoji.id || reactionEmoji.name;
|
|
||||||
const existing = this.cache.get(id);
|
|
||||||
if (!this._partial(reactionEmoji)) return existing;
|
|
||||||
const data = await this.client.api
|
|
||||||
.channels(this.message.channel.id)
|
|
||||||
.messages(this.message.id)
|
|
||||||
.get();
|
|
||||||
if (this.message.partial) this.message._patch(data);
|
|
||||||
if (!data.reactions || !data.reactions.some(r => (r.emoji.id || r.emoji.name) === id)) {
|
|
||||||
reactionEmoji.reaction._patch({ count: 0 });
|
|
||||||
this.message.reactions.cache.delete(id);
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
for (const reaction of data.reactions) {
|
|
||||||
if (this._partial(reaction.emoji)) this.add(reaction, cache);
|
|
||||||
}
|
|
||||||
return existing;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = ReactionManager;
|
module.exports = ReactionManager;
|
||||||
|
|||||||
@@ -101,8 +101,12 @@ class MessageReaction {
|
|||||||
* Fetch this reaction.
|
* Fetch this reaction.
|
||||||
* @returns {Promise<MessageReaction>}
|
* @returns {Promise<MessageReaction>}
|
||||||
*/
|
*/
|
||||||
fetch() {
|
async fetch() {
|
||||||
return this.message.reactions._fetchReaction(this.emoji, true);
|
const message = await this.message.fetch();
|
||||||
|
const existing = message.reactions.cache.get(this.emoji.id || this.emoji.name);
|
||||||
|
// The reaction won't get set when it has been completely removed
|
||||||
|
this._patch(existing || { count: 0 });
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
toJSON() {
|
toJSON() {
|
||||||
|
|||||||
Reference in New Issue
Block a user