Repository navigation
Expand file tree
/
Copy pathdeploy.js
More file actions
40 lines (35 loc) · 1.49 KB
/
Copy pathdeploy.js
File metadata and controls
40 lines (35 loc) · 1.49 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
const fs = require('fs');
const { REST, Routes } = require('discord.js');
const { clientId, guildId, token } = require('./config.json');
// Commands read from the source modules when building their config (e.g. dict choices)
global.log = { out: console.log, audit: console.log, warn: console.warn, error: console.error, debug: console.log };
// Load source files without starting them
const srcfiles = fs.readdirSync('./src').filter(file => file.endsWith('.js'));
for (const file of srcfiles) {
console.log(`Loading source: ${file}`);
const name = file.slice(0, -3);
global[name] = require(`./src/${file}`);
}
const commands = [];
const commandfiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandfiles) {
console.log(`Loading command: ${file}`);
const command = require(`./commands/${file}`);
if (command.config) {
if (command.config.chat) commands.push(command.config.chat);
if (command.config.user) commands.push(command.config.user);
if (command.config.mesg) commands.push(command.config.mesg);
}
else { console.error(`Command provides no config: ${file}`); }
}
const rest = new REST().setToken(token);
(async () => {
try {
await rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: commands });
console.log(`Successfully registered ${commands.length} application commands.`);
}
catch (error) {
console.error(error);
process.exitCode = 1;
}
})();