Files
discord.js/src/client/actions/MessageReactionAdd.js
2016-11-17 03:03:51 -05:00

44 lines
1.1 KiB
JavaScript
Raw Blame History

const Action = require('./Action');
const Constants = require('../../util/Constants');
/*
{ user_id: 'id',
message_id: 'id',
emoji: { name: '<27>', id: null },
channel_id: 'id' } }
*/
class MessageReactionAdd extends Action {
handle(data) {
const user = this.client.users.get(data.user_id);
if (!user) return false;
const channel = this.client.channels.get(data.channel_id);
if (!channel || channel.type === 'voice') return false;
const message = channel.messages.get(data.message_id);
if (!message) return false;
if (!data.emoji) return false;
const reaction = message._addReaction(data.emoji, user);
if (reaction) {
this.client.emit(Constants.Events.MESSAGE_REACTION_ADD, reaction, user);
}
return {
message,
reaction,
user,
};
}
}
/**
* Emitted whenever a reaction is added to a message.
* @event Client#messageReactionAdd
* @param {MessageReaction} messageReaction The reaction object.
* @param {User} user The user that applied the emoji or reaction emoji.
*/
module.exports = MessageReactionAdd;