This repository has been archived by the owner on May 22, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
index.js
50 lines (43 loc) · 1.49 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
43
44
45
46
47
48
49
50
"use strict";
const { Client, Collection } = require("discord.js");
const klaw = require("klaw");
const { sep, resolve, parse } = require("path");
const credentials = require("./credentials");
const client = new Client();
client.commands = new Collection();
client.aliases = new Collection();
client.music = {};
client.config = require("./config");
require("./server/app")(client);
function loadCommand(commandPath) {
try {
const command = require(commandPath);
client.commands.set(command.name.trim().toLowerCase(), command);
command.aliases.forEach((alias) => {
client.aliases.set(alias, command.name);
});
console.log(`Command ${command.name} loaded !`);
} catch (error) {
console.error(error);
}
}
function loadEvent(eventPath) {
try {
const event = require(eventPath);
client.on(event.name.trim(), (...args) => event.execute(client, ...args));
console.log(`Command ${event.name} loaded !`);
} catch (error) {
console.error(error);
}
}
klaw(resolve(__dirname, "commands")).on("data", (item) => {
const cmdFile = parse(item.path);
if (!cmdFile.ext || cmdFile.ext !== ".js") return;
loadCommand(`${cmdFile.dir}${sep}${cmdFile.name}${cmdFile.ext}`);
});
klaw(resolve(__dirname, "events")).on("data", (item) => {
const cmdFile = parse(item.path);
if (!cmdFile.ext || cmdFile.ext !== ".js") return;
loadEvent(`${cmdFile.dir}${sep}${cmdFile.name}${cmdFile.ext}`);
});
client.login(credentials.DISCORD_TOKEN); // token is in process.env.DISCORD_TOKEN