@power-bots/powerbotlibrary 0.0.4 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/main.d.ts +3 -0
- package/dist/main.js +27 -24
- package/package.json +1 -1
package/dist/main.d.ts
CHANGED
package/dist/main.js
CHANGED
|
@@ -47,44 +47,47 @@ class Bot {
|
|
|
47
47
|
discord_js_1.GatewayIntentBits.MessageContent
|
|
48
48
|
] });
|
|
49
49
|
// IMPORT COMMANDS
|
|
50
|
-
|
|
51
|
-
|
|
50
|
+
this.commands = new discord_js_1.Collection();
|
|
51
|
+
this.commandsArray = [];
|
|
52
52
|
const foldersPath = node_path_1.default.join(dirname, 'commands');
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
const
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
else {
|
|
61
|
-
commandFiles = [""];
|
|
62
|
-
}
|
|
63
|
-
for (const file of commandFiles) {
|
|
64
|
-
const filePath = node_path_1.default.join(commandsPath, file);
|
|
65
|
-
const command = require(filePath);
|
|
66
|
-
if ('data' in command && 'execute' in command) {
|
|
67
|
-
this.log.info(`"${command.data.name}" command was imported from ${filePath}`);
|
|
68
|
-
commands.set(command.data.name, command);
|
|
69
|
-
commandsArray.push(command.data.toJSON());
|
|
53
|
+
if (node_fs_1.default.existsSync(foldersPath)) {
|
|
54
|
+
const commandFolders = node_fs_1.default.readdirSync(foldersPath);
|
|
55
|
+
for (const folder of commandFolders) {
|
|
56
|
+
const commandsPath = node_path_1.default.join(foldersPath, folder);
|
|
57
|
+
let commandFiles;
|
|
58
|
+
if (node_fs_1.default.statSync(commandsPath).isDirectory()) {
|
|
59
|
+
commandFiles = node_fs_1.default.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
|
|
70
60
|
}
|
|
71
61
|
else {
|
|
72
|
-
|
|
62
|
+
commandFiles = [""];
|
|
63
|
+
}
|
|
64
|
+
for (const file of commandFiles) {
|
|
65
|
+
const filePath = node_path_1.default.join(commandsPath, file);
|
|
66
|
+
const command = require(filePath);
|
|
67
|
+
if ('data' in command && 'execute' in command) {
|
|
68
|
+
this.commands.set(command.data.name, command);
|
|
69
|
+
this.commandsArray.push(command.data.toJSON());
|
|
70
|
+
}
|
|
71
|
+
else {
|
|
72
|
+
this.log.warn(`The command at ${filePath} is missing a required "data" or "execute" property.`);
|
|
73
|
+
}
|
|
74
|
+
;
|
|
73
75
|
}
|
|
74
76
|
;
|
|
75
77
|
}
|
|
76
78
|
;
|
|
77
79
|
}
|
|
78
|
-
;
|
|
79
80
|
// LOGIN CLIENT
|
|
80
81
|
this.client.once(discord_js_1.Events.ClientReady, (readyClient) => {
|
|
81
82
|
this.log.info(`Logged in as ${readyClient.user.tag}`);
|
|
82
83
|
// REGISTER COMMANDS
|
|
84
|
+
if (this.commandsArray.length === 0)
|
|
85
|
+
return;
|
|
83
86
|
const rest = new discord_js_1.REST().setToken(botToken);
|
|
84
87
|
(() => __awaiter(this, void 0, void 0, function* () {
|
|
85
88
|
try {
|
|
86
|
-
this.log.info(`Started refreshing ${commandsArray.length} application (/) commands.`);
|
|
87
|
-
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: commandsArray });
|
|
89
|
+
this.log.info(`Started refreshing ${this.commandsArray.length} application (/) commands.`);
|
|
90
|
+
const data = yield rest.put(discord_js_1.Routes.applicationCommands(readyClient.user.id), { body: this.commandsArray });
|
|
88
91
|
this.log.info(`Successfully reloaded ${data.length} application (/) commands.`);
|
|
89
92
|
}
|
|
90
93
|
catch (error) {
|
|
@@ -99,7 +102,7 @@ class Bot {
|
|
|
99
102
|
this.client.on(discord_js_1.Events.InteractionCreate, (interaction) => __awaiter(this, void 0, void 0, function* () {
|
|
100
103
|
try {
|
|
101
104
|
if (interaction.isChatInputCommand()) {
|
|
102
|
-
const command = commands.get(interaction.commandName);
|
|
105
|
+
const command = this.commands.get(interaction.commandName);
|
|
103
106
|
if (!command) {
|
|
104
107
|
this.log.error(`No command matching ${interaction.commandName} was found.`);
|
|
105
108
|
return;
|