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