Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const commands = [];
- const foldersPath = path.join(__dirname, 'commands');
- const commandFolders = fs.readdirSync(foldersPath);
- for (const folder of commandFolders) {
- const commandsPath = path.join(foldersPath, folder);
- const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));
- for (const file of commandFiles) {
- const filePath = path.join(commandsPath, file);
- const command = require(filePath);
- if ('data' in command && 'execute' in command) {
- commands.push(command.data.toJSON());
- } else {
- console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
- }
- }
- }
- const rest = new REST().setToken(token);
- (async () => {
- try {
- console.log('Before resetting global commands...');
- await rest.put(
- Routes.applicationCommands(clientId),
- { body: [] },
- );
- console.log('After resetting global commands...');
- } catch (error) {
- console.error('Failed to reset global commands:', error);
- }
- })();
- (async () => {
- try {
- console.log('Before resetting guild commands...');
- await rest.put(
- Routes.applicationGuildCommands(clientId, guildId),
- { body: [] },
- );
- console.log('After resetting guild commands...');
- } catch (error) {
- console.error('Failed to reset guild commands:', error);
- }
- })();
- (async () => {
- try {
- console.log(`Started refreshing ${commands.length} application (/) commands.`);
- const data = await rest.put(
- Routes.applicationCommands(clientId),
- { body: commands },
- );
- console.log(`Successfully reloaded ${data.length} application (/) commands.`);
- } catch (error) {
- console.error('Failed to register commands:', error);
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement