import * as fs from 'node:fs'; import * as path from 'node:path'; import { REST } from '@discordjs/rest'; import { Routes } from 'discord-api-types/v9'; import { ApplicationCommandDataResolvable } from 'discord.js'; import { ApplicationCommandTypes } from 'discord.js/typings/enums'; import config from "./config/botconfig" import { CommandType } from './typings/Command'; // Place your client and guild ids here const clientId = '799504962740289546' //test bot const guildId = '798046052053286924' const rest = new REST({ version: '9' }).setToken(config.Token); async function importFile(filePath: string) { return (await import(filePath))?.default; } (async () => { const commands: ApplicationCommandDataResolvable[] = [] for (const category of fs.readdirSync(`${__dirname}/commands/slash`)) { for (const fileName of fs.readdirSync(`${__dirname}/commands/slash/${category}`).filter(cmd => cmd.endsWith('.ts'))) { const filePath = `${__dirname}/commands/slash/${category}/${fileName}`; const command: CommandType = await importFile(filePath.toString()); if ([ApplicationCommandTypes.MESSAGE, ApplicationCommandTypes.USER].includes(command.type)) delete command.description; if (!command.name) return; commands.push(command); } } //console.log(commands) try { console.log('Started refreshing application (/) commands.'); await rest.put( Routes.applicationGuildCommands(clientId, guildId), { body: [] }, ) // await rest.put( // Routes.applicationCommands(clientId), // { body: commands }, // ) console.log('Successfully reloaded application (/) commands.'); } catch (error) { console.error(error); } process.exit(0) })()