-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommandHandler.js
More file actions
30 lines (27 loc) · 919 Bytes
/
commandHandler.js
File metadata and controls
30 lines (27 loc) · 919 Bytes
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
const { Collection } = require("discord.js");
const fs = require("fs");
let client;
exports.loadCommands = (c) => {
client = c;
client.commands = new Collection();
const commandFiles = fs.readdirSync("./commands").filter(file => file.endsWith(".js"));
for (file of commandFiles) {
const command = require(`./commands/${file}`);
client.commands.set(command.name, command);
}
}
exports.run = (message, prefix) => {
let args = message.content.slice(1).trim().split(/ +/g);
let cmd = args.shift();
let command = client.commands.get(cmd);
if (command) {
try {
command.run(message, args).then(valid => {
if (!valid)
message.channel.send(`Usage: ${prefix}${command.usage}`);
});
} catch (error) {
console.log(`Error during ${command.name} command: ${error.stack}`);
}
}
}