Why do I have my commands twice?

11 Replies
d.js toolkit
d.js toolkit•11mo 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. - Issue solved? Press the button!
Serial Designation N
Serial Designation N•11mo ago
deploy-commands.js now:
require("dotenv").config();

const fs = require("fs");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");

const commands = [];
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"));

commandFiles.forEach(commandFile => {
const command = require(`./commands/${commandFile}`);
if (command.data) {
commands.push(command.data.toJSON());
}
});

const restClient = new REST({ version: "9" }).setToken(process.env.DISCORD_BOT_TOKEN);

restClient.put(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), { body: commands })
.then(() => console.log("Successfully registered commands!"))
.catch(console.error);
require("dotenv").config();

const fs = require("fs");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");

const commands = [];
const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"));

commandFiles.forEach(commandFile => {
const command = require(`./commands/${commandFile}`);
if (command.data) {
commands.push(command.data.toJSON());
}
});

const restClient = new REST({ version: "9" }).setToken(process.env.DISCORD_BOT_TOKEN);

restClient.put(Routes.applicationCommands(process.env.DISCORD_APPLICATION_ID), { body: commands })
.then(() => console.log("Successfully registered commands!"))
.catch(console.error);
Before i changed it:
require("dotenv").config()

const fs = require("fs")

const { REST } = require("@discordjs/rest")

const { Routes } = require("discord-api-types/v9")

const commands = []

const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))

commandFiles.forEach(commandFile => {
const command = require(`./commands/${commandFile}`)
if (command.data)
{
commands.push(command.data.toJSON())
}


})


const restClient = new REST({version: "9"}).setToken(process.env.DISCORD_BOT_TOKEN)

restClient.put(Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, process.env.DISCORD_GUILD_ID),
{body: commands})
.then(() => console.log("Succesfully registered Commands!"))
.catch(console.error)
require("dotenv").config()

const fs = require("fs")

const { REST } = require("@discordjs/rest")

const { Routes } = require("discord-api-types/v9")

const commands = []

const commandFiles = fs.readdirSync("./src/commands").filter(file => file.endsWith(".js"))

commandFiles.forEach(commandFile => {
const command = require(`./commands/${commandFile}`)
if (command.data)
{
commands.push(command.data.toJSON())
}


})


const restClient = new REST({version: "9"}).setToken(process.env.DISCORD_BOT_TOKEN)

restClient.put(Routes.applicationGuildCommands(process.env.DISCORD_APPLICATION_ID, process.env.DISCORD_GUILD_ID),
{body: commands})
.then(() => console.log("Succesfully registered Commands!"))
.catch(console.error)
Shaurya
Shaurya•11mo ago
Because you deploy to both globally and in the guild
Serial Designation N
Serial Designation N•11mo ago
how can i delete the copys? i want it just globally, not both
Shaurya
Shaurya•11mo ago
by registering it only globally, check guide for it
Serial Designation N
Serial Designation N•11mo ago
on other server, there are no copys. only on my own guild. when i removed the commands from code and run the code again, the copys dissapeared but there was still the other commands left but without any function
Shaurya
Shaurya•11mo ago
redeploy it properly
chewie 🌈
chewie 🌈•11mo ago
You have to delete the old ones first
Serial Designation N
Serial Designation N•11mo ago
how?
chewie 🌈
chewie 🌈•11mo ago
Run that with an empty array
Serial Designation N
Serial Designation N•11mo ago
hmm oh wait i wil try it worked. i used accidently this one to redeploy XD thats why the guild one was still there