import { REST, RESTPostAPIChatInputApplicationCommandsJSONBody, Routes } from "npm:discord.js"; const { clientId, guildId, token } = Deno.env.toObject(); import { Command } from "../src/types.ts"; import { gatherPaths } from "../src/gatherer.ts"; const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = []; async function register(commandPath: string) { const { default: command }: { default: Command } = await import(commandPath); if ("data" in command && "execute" in command) { commands.push(command.data.toJSON()); console.log(`Deploying ${command.data.name}...`); } else { console.log( `[WARNING] The command at ${commandPath} is missing a required "data" or "execute" property.` ); } } for (const commandPath of await gatherPaths("commands")) { await register(commandPath) } const rest = new REST().setToken(token); (async () => { try { console.log( `Started refreshing ${commands.length} application (/) commands.` ); await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: commands } ); console.log( `Successfully reloaded ${commands.length} application (/) commands.` ); } catch (error) { console.error(error); } })();