Slash commands being duplicated in global registering

Hey, When I try to register my slash commands globally, they are getting duplicated. Here is the code I am using:
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const fs = require('fs');
const clientId = 'cliend_id';
const guildId = 'guild_id';
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.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command)
}

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

(async () => {
try {
console.log('Started refreshing application (/) commands.');
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 = 'cliend_id';
const guildId = 'guild_id';
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.slashCommandArray.push(command.data.toJSON());
client.slashcommands.set(command.data.name, command)
}

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

(async () => {
try {
console.log('Started refreshing application (/) commands.');
rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: client.slashCommandArray
})
console.log('Started refreshing application (/) commands.');
} catch (error) {
console.error(error);
}
})();
}
}
}
I am using discord.js v13.8.0 and node.js v16
2 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
d.js docs
d.js docs3y ago
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: [] })
Want results from more Discord servers?
Add your server