buddy

node MVC discord bot
Log | Files | Refs | README

ChannelDelete.js (969B)


      1 'use strict';
      2 
      3 const Action = require('./Action');
      4 const DMChannel = require('../../structures/DMChannel');
      5 const { Events } = require('../../util/Constants');
      6 
      7 class ChannelDeleteAction extends Action {
      8   constructor(client) {
      9     super(client);
     10     this.deleted = new Map();
     11   }
     12 
     13   handle(data) {
     14     const client = this.client;
     15     let channel = client.channels.cache.get(data.id);
     16 
     17     if (channel) {
     18       client.channels.remove(channel.id);
     19       channel.deleted = true;
     20       if (channel.messages && !(channel instanceof DMChannel)) {
     21         for (const message of channel.messages.cache.values()) {
     22           message.deleted = true;
     23         }
     24       }
     25       /**
     26        * Emitted whenever a channel is deleted.
     27        * @event Client#channelDelete
     28        * @param {DMChannel|GuildChannel} channel The channel that was deleted
     29        */
     30       client.emit(Events.CHANNEL_DELETE, channel);
     31     }
     32 
     33     return { channel };
     34   }
     35 }
     36 
     37 module.exports = ChannelDeleteAction;