-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathload.js
More file actions
53 lines (37 loc) · 1.99 KB
/
load.js
File metadata and controls
53 lines (37 loc) · 1.99 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
require('colors');
const fs = require("fs");
module.exports = async (client) => {
let cmdDir = `./commands/`;
let group = fs.readdirSync(cmdDir);
for ( category of group ) {
let dir = `${cmdDir}${category}/`;
console.log(category);
fs.readdir(dir, (err, files) => { // Reads all files from "commands" folder
if (err) throw err;
let c = dir.split("/")[2];
let cmds = files.filter(f => f.split('.').pop() === 'js'); // Array contains all files with 'js' extension
if (!cmds.length) return console.log(`No command files found in ${c}...`.red);
console.log(`Loading ${files.length} commands from ${c}...`.magenta); // Prints how many commands we are loading
cmds.forEach((f, i) => { // For all files in folder, f is files, and i is index
const cmd = require(`${dir}${f}`);
client.commands.set(cmd.help.name, cmd); // Push command name and functions into list
console.log(`${i + 1}: ${f} loaded!`.cyan);
});
});
}
client.commands = new client.discord.Collection();
fs.readdir(`./events/`, (err, files) => {
if (err) return console.error(err);
let events = files.filter(f => f.split('.').pop() === 'js');
if (!events.length) return console.log('No event files found...'.red);
console.log(`Loading ${files.length} events...`.magenta);
files.forEach((file, i) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
let eventName = file.split(".")[0]; //Cut out everything from .
client.on(eventName, event.bind(null, client)); // attach file to discord event
delete require.cache[require.resolve(`./events/${file}`)]; // Refresh stored Cache for specific file
console.log(`${i + 1}: ${file} loaded!`.cyan);
});
});
}