buddy

node MVC discord bot
Log | Files | Refs | README

MessageReactionRemove.js (1189B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 const { Events } = require('../../util/Constants');
      5 
      6 /*
      7 { user_id: 'id',
      8      message_id: 'id',
      9      emoji: { name: '�', id: null },
     10      channel_id: 'id' } }
     11 */
     12 
     13 class MessageReactionRemove extends Action {
     14   handle(data) {
     15     if (!data.emoji) return false;
     16 
     17     const user = this.getUser(data);
     18     if (!user) return false;
     19 
     20     // Verify channel
     21     const channel = this.getChannel(data);
     22     if (!channel || channel.type === 'voice') return false;
     23 
     24     // Verify message
     25     const message = this.getMessage(data, channel);
     26     if (!message) return false;
     27 
     28     // Verify reaction
     29     const reaction = this.getReaction(data, message, user);
     30     if (!reaction) return false;
     31     reaction._remove(user);
     32     /**
     33      * Emitted whenever a reaction is removed from a cached message.
     34      * @event Client#messageReactionRemove
     35      * @param {MessageReaction} messageReaction The reaction object
     36      * @param {User} user The user whose emoji or reaction emoji was removed
     37      */
     38     this.client.emit(Events.MESSAGE_REACTION_REMOVE, reaction, user);
     39 
     40     return { message, reaction, user };
     41   }
     42 }
     43 
     44 module.exports = MessageReactionRemove;