@hyperneutrino/djs-lite 1.4.7 → 1.5.0
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 +20 -12
- package/package.json +1 -1
package/index.ts
CHANGED
|
@@ -185,7 +185,7 @@ async function loadSubcommandsAndGroups(directory: string): Promise<{
|
|
|
185
185
|
};
|
|
186
186
|
}
|
|
187
187
|
|
|
188
|
-
export async function loadCommands(client: Client<true>, directory: string,
|
|
188
|
+
export async function loadCommands(client: Client<true>, directory: string, guildId?: string) {
|
|
189
189
|
const commandData: (ChatInputApplicationCommandData | UserApplicationCommandData | MessageApplicationCommandData)[] = [];
|
|
190
190
|
|
|
191
191
|
const slashCommandHandlers = new Map<string, Handler<ChatInputCommandInteraction>>();
|
|
@@ -224,19 +224,27 @@ export async function loadCommands(client: Client<true>, directory: string, opti
|
|
|
224
224
|
else if (interaction.isAutocomplete()) slashCommandAutocompletes.get(interaction.commandName)?.(interaction);
|
|
225
225
|
});
|
|
226
226
|
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
await
|
|
235
|
-
|
|
236
|
-
|
|
227
|
+
const commandDataHasBeenUpdated = await fs
|
|
228
|
+
.readFile(".cache/command-data.json")
|
|
229
|
+
.then((buffer) => buffer.toString("utf-8"))
|
|
230
|
+
.then((string) => JSON.stringify(commandData) !== string)
|
|
231
|
+
.catch(() => true);
|
|
232
|
+
|
|
233
|
+
if (commandDataHasBeenUpdated) {
|
|
234
|
+
await fs.mkdir(".cache", { recursive: true }).catch(() => null);
|
|
235
|
+
await fs.writeFile(".cache/command-data.json", JSON.stringify(commandData)).catch(() => null);
|
|
236
|
+
|
|
237
|
+
if (guildId) {
|
|
238
|
+
const testGuild = client.guilds.resolve(guildId);
|
|
239
|
+
if (!testGuild)
|
|
240
|
+
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.`);
|
|
241
|
+
await testGuild.commands.set(commandData);
|
|
242
|
+
} else {
|
|
243
|
+
await client.application.commands.set(commandData);
|
|
244
|
+
}
|
|
237
245
|
}
|
|
238
246
|
|
|
239
|
-
return { commands: commandData, slashCommandHandlers, userCommandHandlers, messageCommandHandlers };
|
|
247
|
+
return { commands: commandData, slashCommandHandlers, userCommandHandlers, messageCommandHandlers, setCommands: commandDataHasBeenUpdated };
|
|
240
248
|
}
|
|
241
249
|
|
|
242
250
|
export async function loadInteractions(client: Client, directory: string, argumentSeparator: string = ":") {
|