-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.js
56 lines (45 loc) · 1.63 KB
/
bot.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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
const { Client, Collection, Intents } = require('discord.js');
const fs = require('fs');
const AJintents = new Intents(5839);
const { config } = require('dotenv');
// .env processes. (vault)
config({
path: `${__dirname}/.env`
});
// Create commands.
const client = new Client({ intents: AJintents });
client.commands = new Collection();
//-----------------------------
// command handling.
const commandFiles = fs.readdirSync('./src/commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./src/commands/${file}`);
// Set a new item in the Collection
// With the key as the command name and the value as the exported module
client.commands.set(command.data.name, command);
}
//-----------------------------
// event handling for slash commands.
const eventFiles = fs.readdirSync('./src/events').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./src/events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
// Event handling for message events.
// only listens to JS files.
client.modules = new Collection();
fs.readdir('./src/msgevents/', (err, files) => {
if (err) return console.error;
files.forEach(file => {
if (!file.endsWith('.js')) return;
const evt = require(`./src/msgevents/${file}`);
let evtName = evt.event;
console.log(`Loaded event '${file.split('.')[0]}' triggering on '${evtName}'`);
client.on(evtName, evt.execute.bind(null, client))
});
});
client.login(process.env.TOKEN)