-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommandHandler.js
More file actions
42 lines (34 loc) · 1.35 KB
/
Copy pathCommandHandler.js
File metadata and controls
42 lines (34 loc) · 1.35 KB
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 Discord = require('discord.js');
const path = require('path');
const fs = require('fs');
class CommandHandler {
constructor() {
this.commands = [];
this.orig_commands = [];
}
genCommandList(cmdPath="commands") {
let commandsPath = path.join(__dirname, cmdPath);
let commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
for (let file of commandFiles) {
let cmd = require(`./${cmdPath}/${file}`);
this.orig_commands.push(cmd);
this.commands.push(cmd.data.toJSON());
if (!('data' in cmd && 'execute' in cmd)) {
console.log(`[WARNING] The command ${(cmd.data && cmd.data.name) ? cmd.data.name : "[undefined]"} is missing a required "data" or "execute" property.`);
}
}
}
async init(rest, clientID) {
try {
console.log(`Started refreshing ${this.commands.length} application (/) commands.`);
const data = await rest.put(
Discord.Routes.applicationCommands(clientID),
{ body: this.commands },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {
console.error(error);
}
}
}
module.exports = CommandHandler;