mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-13 10:03:31 +01:00
Clean up reactions, add remove all reactions (#890)
* Clean up reactions, add remove all reactions * Reorganize reactions * Re-add Gawdl3y's precious little inline * Update Message.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
a359f344d8
commit
5ed8098af8
@@ -26,7 +26,7 @@ class Message {
|
||||
if (data) this.setup(data);
|
||||
}
|
||||
|
||||
setup(data) {
|
||||
setup(data) { // eslint-disable-line complexity
|
||||
/**
|
||||
* The ID of the message (unique in the channel it was sent)
|
||||
* @type {string}
|
||||
@@ -389,20 +389,23 @@ class Message {
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a reaction to the message
|
||||
* @param {Emoji|ReactionEmoji|string} emoji Emoji to react with
|
||||
* Add a reaction to the message
|
||||
* @param {string|Emoji|ReactionEmoji} emoji Emoji to react with
|
||||
* @returns {Promise<MessageReaction>}
|
||||
*/
|
||||
react(emoji) {
|
||||
if (emoji.identifier) {
|
||||
emoji = emoji.identifier;
|
||||
} else if (typeof emoji === 'string') {
|
||||
if (!emoji.includes('%')) emoji = encodeURIComponent(emoji);
|
||||
} else {
|
||||
return Promise.reject('The emoji must be a string or an Emoji/ReactionEmoji.');
|
||||
}
|
||||
emoji = this.client.resolver.resolveEmojiIdentifier(emoji);
|
||||
if (!emoji) throw new TypeError('Emoji must be a string or Emoji/ReactionEmoji');
|
||||
|
||||
return this.client.rest.methods.addMessageReaction(this.channel.id, this.id, emoji);
|
||||
return this.client.rest.methods.addMessageReaction(this, emoji);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all reactions from a message
|
||||
* @returns {Promise<Message>}
|
||||
*/
|
||||
clearReactions() {
|
||||
return this.client.rest.methods.removeMessageReactions(this);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -523,6 +526,10 @@ class Message {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
_clearReactions() {
|
||||
this.reactions.clear();
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Message;
|
||||
|
||||
@@ -64,7 +64,7 @@ class MessageReaction {
|
||||
user = this.message.client.resolver.resolveUserID(user);
|
||||
if (!user) return Promise.reject('Couldn\'t resolve the user ID to remove from the reaction.');
|
||||
return message.client.rest.methods.removeMessageReaction(
|
||||
message.channel.id, message.id, this.emoji.identifier, user
|
||||
message, this.emoji.identifier, user
|
||||
);
|
||||
}
|
||||
|
||||
@@ -77,7 +77,7 @@ class MessageReaction {
|
||||
fetchUsers(limit = 100) {
|
||||
const message = this.message;
|
||||
return message.client.rest.methods.getMessageReactionUsers(
|
||||
message.channel.id, message.id, this.emoji.identifier, limit
|
||||
message, this.emoji.identifier, limit
|
||||
).then(users => {
|
||||
this.users = new Collection();
|
||||
for (const rawUser of users) {
|
||||
|
||||
Reference in New Issue
Block a user