Double commands

Does anyone have any idea why there are duplications? I have the deploy-commands.js from your guide only I use global commands.
No description
18 Replies
d.js toolkit
d.js toolkit7mo 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!
d.js docs
d.js docs7mo 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: [] })
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
(async () => {
try {
console.log(`Aktualisiere ${commands.length} globale Slash-Commands...`);

const data = await rest.put(
Routes.applicationCommands(CLIENT_ID), // Ändere Route für globale Commands
{ body: commands }
);
(async () => {
try {
console.log(`Aktualisiere ${commands.length} globale Slash-Commands...`);

const data = await rest.put(
Routes.applicationCommands(CLIENT_ID), // Ändere Route für globale Commands
{ body: commands }
);
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
It is
js
require('dotenv').config({ path: '/home/discordbot/src/.env' });
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');

// Konfiguration aus .env
const { DISCORD_TOKEN, CLIENT_ID } = process.env;

if (!DISCORD_TOKEN || !CLIENT_ID) {
throw new Error("Fehlende Umgebungsvariablen! Überprüfe .env-Datei.");
}

const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); // Nur .js-Dateien lesen

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] Command ${filePath} fehlt "data" oder "execute".`);
}
}

const rest = new REST().setToken(DISCORD_TOKEN);

(async () => {
try {
console.log(`Aktualisiere ${commands.length} globale Slash-Commands...`);



const data = await rest.put(
Routes.applicationCommands(CLIENT_ID), // Ändere Route für globale Commands
{ body: commands }
);

console.log(`Erfolgreich! Globale Commands geladen: ${data.length}`);
} catch (error) {
console.error("Fehler beim Deployen:", error);
}
})();
js
require('dotenv').config({ path: '/home/discordbot/src/.env' });
const { REST, Routes } = require('discord.js');
const fs = require('node:fs');
const path = require('node:path');

// Konfiguration aus .env
const { DISCORD_TOKEN, CLIENT_ID } = process.env;

if (!DISCORD_TOKEN || !CLIENT_ID) {
throw new Error("Fehlende Umgebungsvariablen! Überprüfe .env-Datei.");
}

const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js')); // Nur .js-Dateien lesen

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] Command ${filePath} fehlt "data" oder "execute".`);
}
}

const rest = new REST().setToken(DISCORD_TOKEN);

(async () => {
try {
console.log(`Aktualisiere ${commands.length} globale Slash-Commands...`);



const data = await rest.put(
Routes.applicationCommands(CLIENT_ID), // Ändere Route für globale Commands
{ body: commands }
);

console.log(`Erfolgreich! Globale Commands geladen: ${data.length}`);
} catch (error) {
console.error("Fehler beim Deployen:", error);
}
})();
Maybe u can find the mistake😶
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
Yeah I use the first one
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
const commands = []; mean its n emty Array
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
Ok I try it I think I solved it. I had first the local then I had switched to global but never deleted the local ones before. Thank you I am so a dumb ass xD I just need to read + understand ur Link Only ready without understanding is like Talking to a Stone 🗿 Ty
Unknown User
Unknown User7mo ago
Message Not Public
Sign In & Join Server To View
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
If u do Programming as Hobby without teacher its hard but I try it ❤️ And thx for take some time
Steve
Steve7mo ago
I've had this in the beginning too 😭 Such a stupid issue
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
Ty, jup IT or Programming need some time to understand in theorie and collect some practicly experience
Steve
Steve7mo ago
Ja.
Nicoals Matheisen
Nicoals MatheisenOP7mo ago
Uhi ein deutscher🥰
Steve
Steve7mo ago
Ich bin Niederländisch

Did you find this page helpful?