UNPKG

@zerospacegg/vynthra

Version:
79 lines 3.53 kB
import { REST, Routes, SlashCommandBuilder } from "discord.js"; // import { statsSubcommand } from "./subcommands/stats.js"; import { techTreeDisplayTestSubcommand } from "./subcommands/tech-tree-display-test.js"; import { techTreeSubcommand } from "./subcommands/tech-tree.js"; import { randomizerSoloSubcommand, randomizer1v1Subcommand, randomizer2v2Subcommand, randomizerFfaSubcommand } from "./subcommands/randomizer.js"; export async function deployCommands(config) { // Build the main command with configurable name and subcommands const rootCommandName = config.rootCommandName || "zsgg"; const rootCommandDescription = config.rootCommandDescription || "Search ZeroSpace.gg game data"; // Collect all subcommands (built-in + user-provided) const builtinSubcommands = config.disableBuiltinCommands ? [] : [ // statsSubcommand, techTreeDisplayTestSubcommand, techTreeSubcommand, randomizerSoloSubcommand, randomizer1v1Subcommand, randomizer2v2Subcommand, randomizerFfaSubcommand, ]; const allSubcommands = [ ...builtinSubcommands, ...(config.subcommands || []), ]; // Build the main slash command const commandBuilder = new SlashCommandBuilder() .setName(rootCommandName) .setDescription(rootCommandDescription); // Add all subcommands for (const subcommand of allSubcommands) { commandBuilder.addSubcommand(subcommand.builder); } // Collect all command data const commands = [commandBuilder.toJSON()]; // Create REST instance const rest = new REST().setToken(config.token); try { console.log("🚀 Started refreshing application (/) commands..."); if (config.guildId) { // Deploy to specific guild (for development) console.log(`📝 Deploying ${commands.length} commands to guild ${config.guildId}...`); await rest.put(Routes.applicationGuildCommands(config.clientId, config.guildId), { body: commands }); console.log(`✅ Successfully deployed ${commands.length} guild commands!`); } else { // Deploy globally (for production) console.log(`📝 Deploying ${commands.length} commands globally...`); await rest.put(Routes.applicationCommands(config.clientId), { body: commands, }); console.log(`✅ Successfully deployed ${commands.length} global commands!`); console.log("⏰ Note: Global commands may take up to 1 hour to propagate."); } } catch (error) { console.error("❌ Error deploying commands:", error); throw error; } } export async function deleteCommands(config) { const rest = new REST().setToken(config.token); try { console.log("🗑️ Started deleting application (/) commands..."); if (config.guildId) { // Delete guild commands await rest.put(Routes.applicationGuildCommands(config.clientId, config.guildId), { body: [] }); console.log("✅ Successfully deleted all guild commands!"); } else { // Delete global commands await rest.put(Routes.applicationCommands(config.clientId), { body: [] }); console.log("✅ Successfully deleted all global commands!"); } } catch (error) { console.error("❌ Error deleting commands:", error); throw error; } } //# sourceMappingURL=deploy.js.map