diff --git a/scripts/pushCommands.ts b/scripts/pushCommands.ts index 39ad319..25ee04e 100644 --- a/scripts/pushCommands.ts +++ b/scripts/pushCommands.ts @@ -9,15 +9,21 @@ import Command from "../src/command"; const post: RESTPostAPIApplicationCommandsJSONBody[] = []; const guildId = process.argv.slice(2)[0]; -requireDirectory<{default: Command}, void>(module, "../src/commands", { - visit: function (obj) { - console.log(obj); +const importedCommands = requireDirectory(module, "../src/commands"); + +for (const obj in importedCommands) { + try { + const allExports = importedCommands[obj] as {default: unknown}; + const defaultExport = allExports.default; // eslint-disable-next-line @typescript-eslint/ban-ts-comment - // @ts-ignore - // eslint-disable-next-line @typescript-eslint/no-unsafe-argument, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call - post.push(new obj.default().toRESTPostApplicationCommands()); - }, -}); + // @ts-expect-error + const constructedExport = new defaultExport() as unknown; + if (!(constructedExport instanceof Command)) throw new Error(`${obj}'s default does not extends Command`); + post.push(constructedExport.toRESTPostApplicationCommands()); + } catch (e) { + console.error(e); + } +} const rest = new REST().setToken(config.tokens.Discord);