MessageDeleteBulk.js (1161B)
1 'use strict'; 2 3 const Action = require('./Action'); 4 const Collection = require('../../util/Collection'); 5 const { Events } = require('../../util/Constants'); 6 7 class MessageDeleteBulkAction extends Action { 8 handle(data) { 9 const client = this.client; 10 const channel = client.channels.cache.get(data.channel_id); 11 12 if (channel) { 13 const ids = data.ids; 14 const messages = new Collection(); 15 for (const id of ids) { 16 const message = this.getMessage( 17 { 18 id, 19 guild_id: data.guild_id, 20 }, 21 channel, 22 false, 23 ); 24 if (message) { 25 message.deleted = true; 26 messages.set(message.id, message); 27 channel.messages.cache.delete(id); 28 } 29 } 30 31 /** 32 * Emitted whenever messages are deleted in bulk. 33 * @event Client#messageDeleteBulk 34 * @param {Collection<Snowflake, Message>} messages The deleted messages, mapped by their ID 35 */ 36 if (messages.size > 0) client.emit(Events.MESSAGE_BULK_DELETE, messages); 37 return { messages }; 38 } 39 return {}; 40 } 41 } 42 43 module.exports = MessageDeleteBulkAction;