Skip to content
This repository was archived by the owner on Sep 18, 2024. It is now read-only.

Commit abe0dff

Browse files
committed
1.2.1
Changed `defaultPermissions` to `defaultPermission` to fix a bug that prevented users from disabling slash commands completely before updating the permissions. Updated the command, slash command, and event loading to be more efficient and promotes better practices.
1 parent 5849208 commit abe0dff

File tree

6 files changed

+22
-26
lines changed

6 files changed

+22
-26
lines changed

index.js

+17-21
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ try {
1313
// Load up the discord.js library
1414
const { Client, Collection} = require("discord.js");
1515
// 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");
1817
const Enmap = require("enmap");
1918
const config = require("./config.js");
2019

@@ -60,37 +59,34 @@ const init = async () => {
6059

6160
// Here we load **commands** into memory, as a collection, so they're accessible
6261
// 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);
6765
if (response) console.log(response);
68-
});
66+
}
6967

7068
// 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+
}
8278

8379
// 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) {
8682
const eventName = file.split(".")[0];
8783
client.logger.log(`Loading Event: ${eventName}. 👌`, "log");
8884
const event = require(`./events/${file}`);
8985
// Bind the client to any event, before the existing arguments
9086
// provided by the discord.js event.
9187
// This line is awesome by the way. Just sayin'.
9288
client.on(eventName, event.bind(null, client));
93-
});
89+
}
9490

9591
// Generate a cache of client permissions for pretty perm names in commands.
9692
client.levelCache = {};

package-lock.json

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "guidebot",
3-
"version": "1.0.0",
3+
"version": "1.2.1",
44
"description": "A boilerplate example bot with command handler and reloadable commands. Updated and Maintained by the Idiot's Guide Community",
55
"main": "index.js",
66
"scripts": {

slash/leave.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ exports.commandData = {
99
name: "leave",
1010
description: "Make's the user leave the guild.",
1111
options: [],
12-
defaultPermissions: true,
12+
defaultPermission: true,
1313
};
1414

1515
// Set this to false if you want it to be global.

slash/ping.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ exports.commandData = {
1414
name: "ping",
1515
description: "Pongs when pinged.",
1616
options: [],
17-
defaultPermissions: true,
17+
defaultPermission: true,
1818
};
1919

2020
// Set this to false if you want it to be global.

slash/stats.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ exports.commandData = {
2020
name: "stats",
2121
description: "Show's the bots stats.",
2222
options: [],
23-
defaultPermissions: true,
23+
defaultPermission: true,
2424
};
2525

2626
// Set this to false if you want it to be global.

0 commit comments

Comments
 (0)