buddy

node MVC discord bot
Log | Files | Refs | README

GuildRoleUpdate.js (881B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 const { Events } = require('../../util/Constants');
      5 
      6 class GuildRoleUpdateAction extends Action {
      7   handle(data) {
      8     const client = this.client;
      9     const guild = client.guilds.cache.get(data.guild_id);
     10 
     11     if (guild) {
     12       let old = null;
     13 
     14       const role = guild.roles.cache.get(data.role.id);
     15       if (role) {
     16         old = role._update(data.role);
     17         /**
     18          * Emitted whenever a guild role is updated.
     19          * @event Client#roleUpdate
     20          * @param {Role} oldRole The role before the update
     21          * @param {Role} newRole The role after the update
     22          */
     23         client.emit(Events.GUILD_ROLE_UPDATE, old, role);
     24       }
     25 
     26       return {
     27         old,
     28         updated: role,
     29       };
     30     }
     31 
     32     return {
     33       old: null,
     34       updated: null,
     35     };
     36   }
     37 }
     38 
     39 module.exports = GuildRoleUpdateAction;