[SOLVED] discord.js v14 DiscordAPIError[50035] Invalid Form Body (Base Type Required)

Question

This Content is from Stack Overflow. Question asked by Dave

I have an issue with my discord bot using slashcommands.
To explain how my bot works, its very similar to the other easy tutorial bots.
The bot starts in index.js and loads the commands into a collection from the commands directory. If I want to register new commands, I do that from another file.

Whenever my bot starts, I get this error message, but the bot never stops.

DiscordAPIError[50035]: Invalid Form Body
0.name[BASE_TYPE_REQUIRED]: This field is required
1.name[BASE_TYPE_REQUIRED]: This field is required
2.name[BASE_TYPE_REQUIRED]: This field is required
3.name[BASE_TYPE_REQUIRED]: This field is required
4.name[BASE_TYPE_REQUIRED]: This field is required
5.name[BASE_TYPE_REQUIRED]: This field is required
6.name[BASE_TYPE_REQUIRED]: This field is required
    at SequentialHandler.runRequest (E:JavaScriptmusicbottestnode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:287:15)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async SequentialHandler.queueRequest (E:JavaScriptmusicbottestnode_modules@discordjsrestdistlibhandlersSequentialHandler.cjs:99:14)
    at async REST.request (E:JavaScriptmusicbottestnode_modules@discordjsrestdistlibREST.cjs:52:22)
    at async main (E:JavaScriptmusicbottestsrcindex.js:32:9) {
  rawError: {
    code: 50035,
    errors: {
      '0': [Object],
      '1': [Object],
      '2': [Object],
      '3': [Object],
      '4': [Object],
      '5': [Object],
      '6': [Object]
    },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'PUT',
  url: 'https://discord.com/api/v10/applications/1002251457392820244/guilds/756943363093037076/commands',
  requestBody: {
    files: undefined,
    json: Collection(7) [Map] {
      'clearmsg' => [Object],
      'disconnect' => [Object],
      'join' => [Object],
      'pause' => [Object],
      'play' => [Object],
      'resume' => [Object],
      'stop' => [Object]
    }
  }
}

All my 7 command files look like this:

const {SlashCommandBuilder} = require("@discordjs/builders");
module.exports = {
    data: new SlashCommandBuilder()
        .setName("clearmsg")
        .setDescription("Deletes a certain number of messages")
        .addIntegerOption(option =>
            option.setName("number")
                .setDescription("The number of messages")
                .setRequired(true)
        ),
    async execute(event) {
        const anzahl = event.options.getInteger("number");
        await event.channel.bulkDelete(anzahl, true);
        event.reply({content: `${anzahl} message(s) deleted successfully`, ephemeral: true})
    }

}

My index.js looks like this:

const {DisTube} = require("distube");
const c = require("./../config.json");
const {REST} = require("@discordjs/rest");
const {Routes, InteractionType} = require("discord-api-types/v10");
const fs = require("fs");
const client = new Client({
    intents: [
        "Guilds",
        "GuildMessages",
        "MessageContent",
        "GuildVoiceStates"
    ]
})

const rest = new REST({version: '10'}).setToken(c.token)

async function main() {

    client.commands = new Collection();

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

    commandFiles.forEach(commandFile => {
        const command = require(`../src/commands/${commandFile}`)

        client.commands.set(command.data.name, command)
    })

    try {
        console.log('Started refreshing application (/) commands.');
        await rest.put(Routes.applicationGuildCommands(c.applicationid, c.guildid), {
            body: client.commands,
        });
    } catch (err) {
        console.log(err);
    }
}


main();


client.on('interactionCreate', async event => {
    if (event.type !== InteractionType.ApplicationCommand) return;
    const command = client.commands.get(event.commandName);
    if (command) {
        await command.execute(event)
    }

})



client.DisTube = new DisTube(client, {
    leaveOnStop: false,
    emitNewSongOnly: true,
    emitAddSongWhenCreatingQueue: false,
    emitAddListWhenCreatingQueue: false,
})

client.once("ready", () => {
    console.log("Bot is Online!")
})


client.DisTube.on("finishSong", (queue, song) => {
    const songs = c.songs;
    client.DisTube.play(queue.voice.channel, songs[randomIntFromInterval(songs)], {
        member: queue.clientMember,
        textChannel: queue.textChannel
    })
})


async function randomIntFromInterval(list) {
    return Math.floor(Math.random() * list.length)
}


client.login(c.token);

Does somebody know what should I do to fix that?

Solution

The issue happens during channel creation. The first argument (channel name) has been moved to the name property.

Change

await guild.channels.create(`${customId + "-" + ID}`, {
    type: ChannelType.GuildText,
    parent: parent_ID,
    permissionOverwrites: [
        {
            id: member.id,
            allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
        },
        {
            id: everyone_ID,
            deny: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
        },
    ],
})

To

await guild.channels.create({
    name: `${customId + "-" + ID}`,
    type: ChannelType.GuildText,
    parent: parent_ID,
    permissionOverwrites: [
        {
            id: member.id,
            allow: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
        },
        {
            id: everyone_ID,
            deny: [PermissionsBitField.Flags.ViewChannel, PermissionsBitField.Flags.SendMessages, PermissionsBitField.Flags.ReadMessageHistory],
        },
    ],
})

Answered by James


This Question and Answer are collected from stackoverflow and tested by JTuto community, is licensed under the terms of CC BY-SA 4.0.

people found this article helpful. What about you?