title: DiscordAPIError: Invalid Form Body options[2]: Required options must be placed before non-required options
body: <p>Okay guys so after I posted the first question and got no answer, I almost surfed the whole net, formatted the code but still couldn't find a fix.</p>
  <p>I keep getting this error when I register about 13-14 slash commands using the <code>commands.set()</code> method:</p>
  <pre><code>      throw new DiscordAPIError(data, res.status, request);
              ^
  
  DiscordAPIError: Invalid Form Body
  options[2]: Required options must be placed before non-required options
      at RequestHandler.execute (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async RequestHandler.push (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
      at async GuildApplicationCommandManager.set (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\managers\ApplicationCommandManager.js:146:18) {
    method: 'put',
    path: '/applications/922152514420363285/guilds/933052184432636014/commands',
    code: 50035,
    httpStatus: 400,
  </code></pre>
  <p>This is the source code of the <code>ready.js</code> file where I am registering these commands:</p>
  <pre><code>const { Constants } = require(&quot;discord.js&quot;)
  const {promisify} = require('util')
  const {glob} = require('glob')
  
  const globPromise = promisify(glob);
  
  //const slashregister = require('../../slashregistering')
  module.exports = async(Discord , client) =&gt; {
      console.log('Bot is ready')
      const guild = client.guilds.cache.get('933052184432636014')
      const commands = guild.commands
      var arrayofCommands = new Array()
      var commands1 = [
          {
              name : 'add',
              description : 'Adds two numbers.',
              options : [{
                  name : 'num1',
                  description : 'Number1',
                  required : true,
                  type : Constants.ApplicationCommandOptionTypes.INTEGER
              },
              {
                  name : 'num2',
                  description : 'Number2',
                  required : true,
                  type : Constants.ApplicationCommandOptionTypes.INTEGER
              }
          ]
          }
      ]
     
      const slashcommands = await globPromise(`${process.cwd()}/slashcommands/**/*.js`)
      slashcommands.map((file) =&gt; {
          const value = require(file)
          //delete value.execute
          console.log(value)
          
          arrayofCommands.push(value)
      })
       commands.set(
          arrayofCommands
       )
  }
  </code></pre>
  <p>However, the code should work since the 'file' variable has all the required fields: <code>name</code>, <code>description</code>, <code>type</code>, <code>defaultPermission</code>, and <code>options</code> too.</p>
  <p>So I outputted the object <code>file</code> and this is one of its iterations:</p>
  <p><a href="https://i.stack.imgur.com/wKbbM.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wKbbM.png" alt="enter image description here" /></a></p>
  <p>And the surprising thing is that the <code>commands1</code> array, although having the same properties as that of <code>arrayOfCommands</code> array, WORKS! So could anyone please help me?</p>
  <p>Here is the full error:</p>
  <pre><code>Server is online!
  Bot is ready
  C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\rest\RequestHandler.js:350
        throw new DiscordAPIError(data, res.status, request);
              ^
  
  DiscordAPIError: Invalid Form Body
  options[2]: Required options must be placed before non-required options
      at RequestHandler.execute (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\rest\RequestHandler.js:350:13)
      at processTicksAndRejections (node:internal/process/task_queues:96:5)
      at async RequestHandler.push (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\rest\RequestHandler.js:51:14)
      at async GuildApplicationCommandManager.set (C:\Users\Mihir\Desktop\FunMod\node_modules\discord.js\src\managers\ApplicationCommandManager.js:146:18) {
    method: 'put',
    path: '/applications/922152514420363285/guilds/933052184432636014/commands',
    code: 50035,
    httpStatus: 400,
    requestData: {
      json: [
        {
          name: 'addrole',
          description: 'Gives the member a role.',
          type: 1,
          options: [
            {
              type: 8,
              name: 'role',
              description: 'Role Name',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 6,
              name: 'member',
              description: 'Member ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'ban',
          description: 'Ban the specified member.',
          type: 1,
          options: [
            {
              type: 6,
              name: 'member',
              description: 'Member ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'reason',
              description: 'Reason ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'changenick',
          description: 'Changes the nickname of a server member.',
          type: 1,
          options: [
            {
              type: 6,
              name: 'member',
              description: 'Member',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'nickname',
              description: 'Nickname',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'kick',
          description: 'Kicks the specified member.',
          type: 1,
          options: [
            {
              type: 6,
              name: 'member',
              description: 'Member',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'reason',
              description: 'Reason',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'lock',
          description: 'Locks the specified channel for the specified role.',
          type: 1,
          options: [
            {
              type: 7,
              name: 'channel',
              description: 'Channel',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 8,
              name: 'role',
              description: 'Role ',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'lockdown',
          description: 'Enforces a complete lockdown on the server.',
          type: 1,
          options: [
            {
              type: 3,
              name: 'toggle',
              description: 'on/off',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 8,
              name: 'role',
              description: 'Role ',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'removerole',
          description: 'Removes role from a member.',
          type: 1,
          options: [
            {
              type: 6,
              name: 'member',
              description: 'Member ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 8,
              name: 'role',
              description: 'Role ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'timeout',
          description: 'Gives a member a timeout.',
          type: 1,
          options: [
            {
              type: 6,
              name: 'member',
              description: 'Member ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'reason',
              description: 'Reason',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'time',
              description: 'Duration',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'unlock',
          description: 'Locks the specified channel for the specified role.',
          type: 1,
          options: [
            {
              type: 7,
              name: 'channel',
              description: 'Channel',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 8,
              name: 'role',
              description: 'Role',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'embedcreate',
          description: 'Creates an embed.',
          type: 1,
          options: [
            {
              type: 7,
              name: 'channel',
              description: 'Channel ',
              required: false,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'color',
              description: 'Hex-Code',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'title',
              description: 'Title',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'ping',
          description: 'Responds with a pong!',
          type: 1,
          options: undefined,
          default_permission: false
        },
        {
          name: 'setactivity',
          description: 'Sets the Activity of the bot.',
          type: 1,
          options: [
            {
              type: 3,
              name: 'activity',
              description: 'Activity',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            },
            {
              type: 3,
              name: 'type',
              description: 'Type ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'setavatar',
          description: &quot;Sets the bot's avatar.&quot;,
          type: 1,
          options: [
            {
              type: 3,
              name: 'link',
              description: 'Image Link',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        },
        {
          name: 'setstatus',
          description: 'Sets the status of the bot.',
          type: 1,
          options: [
            {
              type: 3,
              name: 'status',
              description: 'Status ',
              required: true,
              autocomplete: undefined,
              choices: undefined,
              options: undefined,
              channel_types: undefined,
              min_value: undefined,
              max_value: undefined
            }
          ],
          default_permission: false
        }
      ],
      files: []
    }
  }
  [nodemon] app crashed - waiting for file changes before starting...
  </code></pre>