Discord.js v13 Slash commands are duplicated

Hello , I was registering slash commands but I ran into an error: 24[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique
I checked the specified guild and I saw that the commands are duplicated. Why?
Code:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = '966666309909770260';
const guildId = '966987181069598731';
module.exports = (client) => {
    client.handleCommands = async (slashCommandFolders, path) => {
        client.slashCommandArray = [];
        for (folder of slashCommandFolders) {
            const slashCommandFiles = fs.readdirSync(`${path}/${folder}`).filter(file => file.endsWith('.js'));
            for (const file of slashCommandFiles) {
                const command = require(`../slashcommands/${folder}/${file}`);
                client.slashcommands.set(command.data.name, command)
                client.slashCommandArray.push(command.data.toJSON());
            }


            const rest = new REST({ version: '9' }).setToken(process.env.DISCORD_TOKEN);

            (async () => {
                try {
                    console.log('Started refreshing application (/) commands.');
                    await rest.put(
                        Routes.applicationGuildCommands(clientId, guildId),
                        { body: client.slashCommandArray },
                    );

                    console.log('Started refreshing application (/) commands.');
                } catch (error) {
                    console.error(error);
                }
            })();
        }
    }
}

Notes: Using discord.js v13.8.0 node.js v16
Was this page helpful?