Home > Software engineering >  discord.js v13 deploying slash commands doesn't work
discord.js v13 deploying slash commands doesn't work

Time:08-29

I'm trying to deploy a slash commands and it gives me error DiscordAPIError[50035]: Invalid Form Body guild_id[NUMBER_TYPE_COERCE]: Value "undefined" is not snowflake.

const path = require('node:path');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { token, clientId } = require('./config.json');
const fs = require('node:fs');

const commands = [];
const isDirectory = source => fs.lstatSync(source).isDirectory();
const getDirectories = source => fs.readdirSync(source).map(name => path.join(source, name)).filter(isDirectory);


getDirectories(__dirname   '/slash').forEach(category => {
  const commandFiles = fs.readdirSync(category).filter(file => file.endsWith('.js'));

  for(const file of commandFiles) {
    const command = require(`${category}/${file}`);
    commands.push(command.data.toJSON());
  }
});

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

(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(
            Routes.applicationGuildCommands(clientId),
            { body: commands },
        );

        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();

CodePudding user response:

Routes.applicationGuildCommands() requires a guild id as a second parameter.

Define the id of the guild you wish to test the bot on and supply it

Routes.applicationGuildCommands(clientId, guildId)
  • Related