DiscordAPIError[50035]: Invalid Form Body | 5[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique

Viewed 22

This Is My index.js

const LOAD_SLASH = process.argv[2] == "load"

const CLIENT_ID = "981858607362629663"
const GUILD_ID = "970702726348546078"

const client = new Client({
    intents: [
        GatewayIntentBits.Guilds,
        GatewayIntentBits.GuildMessages,
        GatewayIntentBits.MessageContent,
        GatewayIntentBits.GuildMembers,
        GatewayIntentBits.GuildVoiceStates
    ]
})

client.slashcommands = new Discord.Collection()
client.player = new Player(client, {
    ytdlOptions: {
        quality: "highestaudio",
        highWaterMark: 1 << 25
    }
})

let commands = []

const slashFiles = fs.readdirSync("./slash").filter(file => file.endsWith(".js"))
for (const file of slashFiles){
    const slashcmd = require(`./slash/${file}`)
    client.slashcommands.set(slashcmd.data.name, slashcmd)
    if (LOAD_SLASH) commands.push(slashcmd.data.toJSON())
}


I Recieve The Following Error After I Run node index.js load :-

DiscordAPIError[50035]: Invalid Form Body 5[APPLICATION_COMMANDS_DUPLICATE_NAME]: Application command names must be unique at SequentialHandler.runRequest

I have tried uninstalling and re-installing discord.js, still I am experiencing this error, I would really like some help!

2 Answers

You have a duplicate command name somewhere in your files. Try finding it with the following snippet:

const slashFiles = fs.readdirSync("./slash").filter(file => file.endsWith(".js"))
for (const file of slashFiles){
    const slashcmd = require(`./slash/${file}`)
    console.log(slashcmd.data.name)
}

Find the command name which is logged twice and edit the command file accordingly.

In one of the files you duplicated name with another file

Related