-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.ts
54 lines (42 loc) · 1.39 KB
/
index.ts
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import './scripts/load-env';
import Cache from 'node-cache';
import client from './src/client';
import commands from './src/commands/index';
import MessageListener from './src/MessageListener';
client.once('ready', () => {
console.log('Ready!');
});
const commandCache = new Cache();
client.on('interactionCreate', async interaction => {
if (!interaction.isCommand())
return;
const cacheEntry = commandCache.get(interaction.member.user.id) as number | undefined;
if (cacheEntry && cacheEntry > Date.now() - 10_000) {
interaction.reply({
content: 'You are entering commands too quickly!',
ephemeral: true,
});
return;
}
commandCache.set(interaction.member.user.id, Date.now());
const command = commands.get(interaction.commandName);
if (!command)
return;
try {
await command.execute(interaction);
} catch (error) {
console.error(error);
await interaction.reply({
content: 'There was an internal error while executing this command, please tell <@110615438873853952>.',
ephemeral: true,
});
}
});
client.on('messageCreate', MessageListener.onMessageCreate);
client.on('messageUpdate', MessageListener.onMessageUpdate);
client.login(process.env.DISCORD_TOKEN);
process.on('SIGINT', () => {
setTimeout(() => {
client.destroy();
}, 500);
});