This repository was archived by the owner on Mar 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathindex.js
More file actions
83 lines (71 loc) · 2 KB
/
index.js
File metadata and controls
83 lines (71 loc) · 2 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Setup environment
require('dotenv').config();
// Setup client
const { Client, Collection } = require('discord.js');
const client = new Client();
client.login(process.env.TOKEN);
module.exports.client = client;
// Setup music
client.queue = new Map();
// Setup commands
const { fetchFiles } = require('./utils/files');
const commandFiles = fetchFiles('./commands', '.js');
client.categories = new Collection();
client.commands = new Collection();
client.aliases = new Collection();
const categories = [];
for (const path of commandFiles) {
// Get the file
const file = require(path);
// Check the command
if (!file || !file.config || !file.callback) continue;
// Destructuring the config
const { name, aliases, category } = file.config;
// Check the config
if (!name) continue;
// Set commands
client.commands.set(name, file);
if (name.includes('-')) client.aliases.set(name.replace(/-/g, ''), file);
if (aliases) {
// If there are multiple aliases in an array
if (typeof aliases == 'object') {
for (const alias of aliases) {
client.aliases.set(alias, file);
if (alias.includes('-')) {
client.aliases.set(alias.replace(/-/g, ''), file);
}
}
}
// If it is a single alias in a string
if (typeof aliases == 'string') {
client.aliases.set(aliases, file);
if (aliases.includes('-')) {
client.aliases.set(aliases.replace(/-/g, ''), file);
}
}
}
// Store the category
if (category && !categories.includes(category)) {
categories.push(category);
client.categories.set(name, category);
}
}
// Setup events
const eventFiles = fetchFiles('./events', '.js');
for (const event of eventFiles) require(event);
// Log events and commands loaded
console.log(
`${categories.length} categor${
categories.length == 1 ? 'y has' : 'ies have'
} been loaded.`,
);
console.log(
`${client.commands.size} command${
client.commands.size == 1 ? ' has' : 's have'
} been loaded.`,
);
console.log(
`${eventFiles.length} event${
eventFiles.length == 1 ? ' has' : 's have'
} loaded.`,
);