mirror of
https://github.com/discordjs/discord.js.git
synced 2026-06-02 17:10:08 +00:00
41 lines
1.3 KiB
JavaScript
41 lines
1.3 KiB
JavaScript
const Action = require('./Action');
|
||
const { Events } = require('../../util/Constants');
|
||
|
||
/*
|
||
{ user_id: 'id',
|
||
message_id: 'id',
|
||
emoji: { name: '<27>', id: null },
|
||
channel_id: 'id' } }
|
||
*/
|
||
|
||
class MessageReactionRemove extends Action {
|
||
handle(data) {
|
||
const user = this.client.users.get(data.user_id);
|
||
if (!user) return false;
|
||
// Verify channel
|
||
const channel = this.client.channels.get(data.channel_id);
|
||
if (!channel || channel.type === 'voice') return false;
|
||
// Verify message
|
||
const message = channel.messages.get(data.message_id);
|
||
if (!message) return false;
|
||
if (!data.emoji) return false;
|
||
// Verify reaction
|
||
const emojiID = data.emoji.id || decodeURIComponent(data.emoji.name);
|
||
const reaction = message.reactions.get(emojiID);
|
||
if (!reaction) return false;
|
||
reaction._remove(user);
|
||
/**
|
||
* Emitted whenever a reaction is removed from a cached message.
|
||
* @event Client#messageReactionRemove
|
||
* @param {MessageReaction} messageReaction The reaction object
|
||
* @param {User} user The user whose emoji or reaction emoji was removed
|
||
*/
|
||
this.client.emit(Events.MESSAGE_REACTION_REMOVE, reaction, user);
|
||
|
||
return { message, reaction, user };
|
||
}
|
||
}
|
||
|
||
|
||
module.exports = MessageReactionRemove;
|