|
13 | 13 | // Load up the discord.js library
|
14 | 14 | const { Client, Collection} = require("discord.js");
|
15 | 15 | // We also load the rest of the things we need in this file:
|
16 |
| -const { promisify } = require("util"); |
17 |
| -const readdir = promisify(require("fs").readdir); |
| 16 | +const { readdirSync } = require("fs"); |
18 | 17 | const Enmap = require("enmap");
|
19 | 18 | const config = require("./config.js");
|
20 | 19 |
|
@@ -60,37 +59,34 @@ const init = async () => {
|
60 | 59 |
|
61 | 60 | // Here we load **commands** into memory, as a collection, so they're accessible
|
62 | 61 | // here and everywhere else.
|
63 |
| - const cmdFiles = await readdir("./commands/"); |
64 |
| - cmdFiles.forEach(f => { |
65 |
| - if (!f.endsWith(".js")) return; |
66 |
| - const response = client.loadCommand(f); |
| 62 | + const commands = readdirSync("./commands/").filter(file => file.endsWith(".js")); |
| 63 | + for (const file of commands) { |
| 64 | + const response = client.loadCommand(file); |
67 | 65 | if (response) console.log(response);
|
68 |
| - }); |
| 66 | + } |
69 | 67 |
|
70 | 68 | // Now we load any **slash** commands you may have in the ./slash directory.
|
71 |
| - readdir("./slash", (err, files) => { |
72 |
| - if (err) return console.error(err); |
73 |
| - files.forEach(file => { |
74 |
| - if (!file.endsWith(".js")) return; |
75 |
| - const props = require(`./slash/${file}`); |
76 |
| - const commandName = file.split(".")[0]; |
77 |
| - client.logger.log(`Loading Slash command: ${commandName}. 👌`, "log"); |
78 |
| - // Now set the name of the command with it's properties. |
79 |
| - client.slashcmds.set(props.commandData.name, props); |
80 |
| - }); |
81 |
| - }); |
| 69 | + const slashFiles = readdirSync("./slash").filter(file => file.endsWith(".js")); |
| 70 | + for (const file of slashFiles) { |
| 71 | + const command = require(`./slash/${file}`); |
| 72 | + const commandName = file.split(".")[0]; |
| 73 | + client.logger.log(`Loading Slash command: ${commandName}. 👌`, "log"); |
| 74 | + |
| 75 | + // Now set the name of the command with it's properties. |
| 76 | + client.slashcmds.set(command.commandData.name, command); |
| 77 | + } |
82 | 78 |
|
83 | 79 | // Then we load events, which will include our message and ready event.
|
84 |
| - const evtFiles = await readdir("./events/"); |
85 |
| - evtFiles.forEach(file => { |
| 80 | + const eventFiles = readdirSync("./events/").filter(file => file.endsWith(".js")); |
| 81 | + for (const file of eventFiles) { |
86 | 82 | const eventName = file.split(".")[0];
|
87 | 83 | client.logger.log(`Loading Event: ${eventName}. 👌`, "log");
|
88 | 84 | const event = require(`./events/${file}`);
|
89 | 85 | // Bind the client to any event, before the existing arguments
|
90 | 86 | // provided by the discord.js event.
|
91 | 87 | // This line is awesome by the way. Just sayin'.
|
92 | 88 | client.on(eventName, event.bind(null, client));
|
93 |
| - }); |
| 89 | + } |
94 | 90 |
|
95 | 91 | // Generate a cache of client permissions for pretty perm names in commands.
|
96 | 92 | client.levelCache = {};
|
|
0 commit comments