Duplicated commands (not global)

im starting out with a very basic command ping-pong! when i use deploy-command.ts script multiple times, i see the command twice on my server. I don't get why this is happening. Ive followed the guide step by step : https://discordjs.guide/creating-your-bot/slash-commands.html#before-you-continue I can share my code if needed .
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
5 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button!
FirasRG
FirasRG3mo ago
fyi, when i kick the bot from the server and readd it, the command appears once ! this is my deploy-commands.ts
const commands = [] as Command[];

const foldersPath = path.join(__dirname, 'src/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('.ts'));

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(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
) as unknown[];

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {

console.error(error);
}
})();
const commands = [] as Command[];

const foldersPath = path.join(__dirname, 'src/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('.ts'));

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(`Started refreshing ${commands.length} application (/) commands.`);

const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
) as unknown[];

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {

console.error(error);
}
})();
Amgelo
Amgelo3mo ago
are you sure you didn't deploy globally first? the guide first covers how to deploy globally, then per guild
d.js docs
d.js docs3mo 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: [] })
FirasRG
FirasRG3mo ago
Ah thanks Gonna check that out
Want results from more Discord servers?
Add your server