mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-19 04:53:30 +01:00
Add Message Reaction me
This commit is contained in:
@@ -155,6 +155,13 @@ class Message {
|
|||||||
* @type {Collection<string, MessageReaction>}
|
* @type {Collection<string, MessageReaction>}
|
||||||
*/
|
*/
|
||||||
this.reactions = new Collection();
|
this.reactions = new Collection();
|
||||||
|
|
||||||
|
if (data.reactions && data.reactions.length > 0) {
|
||||||
|
for (const reaction of data.reactions) {
|
||||||
|
const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name;
|
||||||
|
this.reactions.set(id, new MessageReaction(this, reaction.emoji, reaction.count, reaction.me));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_addReaction(emoji, user) {
|
_addReaction(emoji, user) {
|
||||||
@@ -162,8 +169,9 @@ class Message {
|
|||||||
let reaction;
|
let reaction;
|
||||||
if (this.reactions.has(emojiID)) {
|
if (this.reactions.has(emojiID)) {
|
||||||
reaction = this.reactions.get(emojiID);
|
reaction = this.reactions.get(emojiID);
|
||||||
|
if (!reaction.me) reaction.me = user.id === this.client.user.id;
|
||||||
} else {
|
} else {
|
||||||
reaction = new MessageReaction(this, emoji, 0);
|
reaction = new MessageReaction(this, emoji, 0, user.id === this.client.user.id);
|
||||||
this.reactions.set(emojiID, reaction);
|
this.reactions.set(emojiID, reaction);
|
||||||
}
|
}
|
||||||
if (!reaction.users.has(user.id)) {
|
if (!reaction.users.has(user.id)) {
|
||||||
@@ -181,6 +189,9 @@ class Message {
|
|||||||
if (reaction.users.has(user.id)) {
|
if (reaction.users.has(user.id)) {
|
||||||
reaction.users.delete(user.id);
|
reaction.users.delete(user.id);
|
||||||
reaction.count--;
|
reaction.count--;
|
||||||
|
if (user.id === this.client.user.id) {
|
||||||
|
reaction.me = false;
|
||||||
|
}
|
||||||
return reaction;
|
return reaction;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -236,6 +247,15 @@ class Message {
|
|||||||
if (chan) this.mentions.channels.set(chan.id, chan);
|
if (chan) this.mentions.channels.set(chan.id, chan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (data.reactions) {
|
||||||
|
this.reactions = new Collection();
|
||||||
|
if (data.reactions.length > 0) {
|
||||||
|
for (const reaction of data.reactions) {
|
||||||
|
const id = reaction.emoji.id ? `${reaction.emoji.name}:${reaction.emoji.id}` : reaction.emoji.name;
|
||||||
|
this.reactions.set(id, new MessageReaction(this, data.emoji, data.count, data.me));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -55,13 +55,17 @@ class ReactionEmoji {
|
|||||||
* Represents a reaction to a message
|
* Represents a reaction to a message
|
||||||
*/
|
*/
|
||||||
class MessageReaction {
|
class MessageReaction {
|
||||||
constructor(message, emoji, count) {
|
constructor(message, emoji, count, me) {
|
||||||
/**
|
/**
|
||||||
* The message that this reaction refers to
|
* The message that this reaction refers to
|
||||||
* @type {Message}
|
* @type {Message}
|
||||||
*/
|
*/
|
||||||
this.message = message;
|
this.message = message;
|
||||||
|
/**
|
||||||
|
* Whether the client has given this reaction
|
||||||
|
* @type {boolean}
|
||||||
|
*/
|
||||||
|
this.me = me;
|
||||||
this._emoji = new ReactionEmoji(this, emoji.name, emoji.id);
|
this._emoji = new ReactionEmoji(this, emoji.name, emoji.id);
|
||||||
/**
|
/**
|
||||||
* The number of people that have given the same reaction.
|
* The number of people that have given the same reaction.
|
||||||
|
|||||||
Reference in New Issue
Block a user