-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
39 lines (31 loc) · 1.08 KB
/
index.js
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
// Load environment variables
require('dotenv').config();
// We need this to load in files configurations
const fs = require('fs');
// The client starts our bot
const { Client, Collection, Intents } = require('discord.js');
const client = new Client({ intents: [Intents.FLAGS.GUILDS] });
// Register commends from commands folder
client.commands = fs.readdirSync('./commands').reduce((acc, file) => {
if (!file.endsWith('.js')) return acc;
const command = require(`./commands/${file}`);
return acc.set(command.data.name, command);
}, new Collection());
// Register events from events folder
fs.readdirSync('./events').forEach(file => {
if (!file.endsWith('.js')) return;
const event = require(`./events/${file}`);
if (event.once) {
client.once(event.name, event.execute);
} else {
client.on(event.name, event.execute);
}
});
(async () => {
// Deploy commands as a REST endpoint...
// Seems pretty redundant considering we're having to
// loop through the commands folder twice
require('./deploy-commands')();
// Lift off!
client.login(process.env.TOKEN);
})();