@hyperneutrino/djs-lite 1.4.7 → 1.5.1
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/index.ts +21 -12
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -120,6 +120,7 @@ async function importAll(
|
|
|
120
120
|
await Promise.all(
|
|
121
121
|
files.map(async (file) => {
|
|
122
122
|
if (file.isDirectory()) return;
|
|
123
|
+
if (file.name.startsWith(".")) return;
|
|
123
124
|
|
|
124
125
|
const absolutePath = path.resolve(file.parentPath, file.name);
|
|
125
126
|
const relativePath = path.join(directory, path.relative(path.resolve(directory), absolutePath));
|
|
@@ -185,7 +186,7 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
|
|
|
185
186
|
};
|
|
186
187
|
}
|
|
187
188
|
|
|
188
|
-
export async function loadCommands(client: Client<true>, directory: string,
|
|
189
|
+
export async function loadCommands(client: Client<true>, directory: string, guildId?: string) {
|
|
189
190
|
const commandData: (ChatInputApplicationCommandData | UserApplicationCommandData | MessageApplicationCommandData)[] = [];
|
|
190
191
|
|
|
191
192
|
const slashCommandHandlers = new Map<string, Handler<ChatInputCommandInteraction>>();
|
|
@@ -224,19 +225,27 @@ export async function loadCommands(client: Client<true>, directory: string, opti
|
|
|
224
225
|
else if (interaction.isAutocomplete()) slashCommandAutocompletes.get(interaction.commandName)?.(interaction);
|
|
225
226
|
});
|
|
226
227
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await
|
|
235
|
-
|
|
236
|
-
|
|
228
|
+
const commandDataHasBeenUpdated = await fs
|
|
229
|
+
.readFile(".cache/command-data.json")
|
|
230
|
+
.then((buffer) => buffer.toString("utf-8"))
|
|
231
|
+
.then((string) => JSON.stringify(commandData) !== string)
|
|
232
|
+
.catch(() => true);
|
|
233
|
+
|
|
234
|
+
if (commandDataHasBeenUpdated) {
|
|
235
|
+
await fs.mkdir(".cache", { recursive: true }).catch(() => null);
|
|
236
|
+
await fs.writeFile(".cache/command-data.json", JSON.stringify(commandData)).catch(() => null);
|
|
237
|
+
|
|
238
|
+
if (guildId) {
|
|
239
|
+
const testGuild = client.guilds.resolve(guildId);
|
|
240
|
+
if (!testGuild)
|
|
241
|
+
throw new Error(`Provided test guild (${guildId}) can not be found, please make sure the bot you started this project on is in this guild.`);
|
|
242
|
+
await testGuild.commands.set(commandData);
|
|
243
|
+
} else {
|
|
244
|
+
await client.application.commands.set(commandData);
|
|
245
|
+
}
|
|
237
246
|
}
|
|
238
247
|
|
|
239
|
-
return { commands: commandData, slashCommandHandlers, userCommandHandlers, messageCommandHandlers };
|
|
248
|
+
return { commands: commandData, slashCommandHandlers, userCommandHandlers, messageCommandHandlers, setCommands: commandDataHasBeenUpdated };
|
|
240
249
|
}
|
|
241
250
|
|
|
242
251
|
export async function loadInteractions(client: Client, directory: string, argumentSeparator: string = ":") {
|