MessageCreate.js (1076B)
1 'use strict'; 2 3 const Action = require('./Action'); 4 const { Events } = require('../../util/Constants'); 5 6 class MessageCreateAction extends Action { 7 handle(data) { 8 const client = this.client; 9 const channel = client.channels.cache.get(data.channel_id); 10 if (channel) { 11 const existing = channel.messages.cache.get(data.id); 12 if (existing) return { message: existing }; 13 const message = channel.messages.add(data); 14 const user = message.author; 15 let member = message.member; 16 channel.lastMessageID = data.id; 17 if (user) { 18 user.lastMessageID = data.id; 19 user.lastMessageChannelID = channel.id; 20 } 21 if (member) { 22 member.lastMessageID = data.id; 23 member.lastMessageChannelID = channel.id; 24 } 25 26 /** 27 * Emitted whenever a message is created. 28 * @event Client#message 29 * @param {Message} message The created message 30 */ 31 client.emit(Events.MESSAGE_CREATE, message); 32 return { message }; 33 } 34 35 return {}; 36 } 37 } 38 39 module.exports = MessageCreateAction;