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);
}
})();
}
}
}
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
10 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
MrMythical
MrMythical3y ago
as in two of each command?
Pooyan
PooyanOP3y ago
yep
d.js docs
d.js docs3y ago
Tag suggestion for @pooyaneftekhari: If you have duplicate commands on your server, you registered both global and guild commands. You can remove the duplicates by resetting either the global or guild commands • Resetting global commands: rest.put(Routes.applicationCommands(clientId), { body: [] }) • Resetting guild commands: rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
Pooyan
PooyanOP3y ago
MrMythical
MrMythical3y ago
the tag shows the fix
Pooyan
PooyanOP3y ago
lemme check
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Pooyan
PooyanOP3y ago
no
client.handleEvents(slashEventFiles, "./slashEvents");
client.handleCommands(slashCommandFolders, "./slashcommands");
client.handleEvents(slashEventFiles, "./slashEvents");
client.handleCommands(slashCommandFolders, "./slashcommands");
this is main.js
MrMythical
MrMythical3y ago
just do the fix as in the tag
Want results from more Discord servers?
Add your server