import { REST } from "@discordjs/rest"; import { Routes } from "discord.js"; import com from './commands' import ConfigManager from "./controller/ConfigManager"; export default function updateCommands(config: ConfigManager) { const commands: any = [] if (!process.env.DISCORD_TOKEN) throw new Error("Token is null"); com.forEach((command: any) => { commands.push(command.data.toJSON() as never) }) const rest = new REST({ version: '10' }).setToken(process.env.DISCORD_TOKEN); (async () => { try { console.log(`Started refreshing ${commands.length} application (/) commands.`); const data: any = await rest.put( Routes.applicationCommands(String(process.env.CLIENT_ID)), { body: commands }, ); console.log(`Successfully reloaded ${data.length} application (/) commands.`); } catch (error) { console.error(error); } })(); }