-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
42 lines (34 loc) · 1.32 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
40
41
42
const fs = require('fs');
const Discord = require('discord.js');
const client = new Discord.Client();
const { prefix, token } = require('./config.json');
client.commands = new Discord.Collection();
// Goes into the commands folder, takes every file with the ending js, and adds them the the client commands
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for(const file of commandFiles) {
const command = require(`./commands/${file}`);
let commandName = file.substring(0, file.length - 3);
client.commands.set(commandName , command);
}
// when the client is ready, run this code
// this event will only trigger one time after logging in
client.once('ready', () => {
console.log('Ready!');
});
client.on('message', message => {
if (!message.content.startsWith(prefix) || message.author.bot) return;
// an array of arguments, uses regex incase user uses more than one space
const args = message.content.slice(prefix.length).split(/ +/);
// holds the command without the prefix in lower case
const command = args.shift().toLowerCase();
if(!client.commands.has(command)) {
return;
}
try {
client.commands.get(command).execute(message, args);
}
catch {
message.reply('Error Occurred!');
}
});
client.login(token);