Home > front end >  DiscordJS v13 Invalid Form Body
DiscordJS v13 Invalid Form Body

Time:05-06

I am trying to make a toggle able slash command, if they pick the disable option it turns it off but when if you pick the enable option it asks to pick a channel but it gives this error

Error:

DiscordAPIError[50035]: Invalid Form Body
23.name[BASE_TYPE_REQUIRED]: This field is required
  rawError: {
    code: 50035,
    errors: { '23': [Object] },
    message: 'Invalid Form Body'
  },
  code: 50035,
  status: 400,
  method: 'put',
  url: 'https://discord.com/api/v9/applications/971024098098569327/commands'

Code:

module.exports = {
    name: 'welcomer',
    permissions: 'MANAGE_CHANNELS',
    description: 'Set Where Welcome Messages Get Sent To.',
    options: [
        {
            name: 'toggle',
            description: 'Toggle On/Off The Welcomer',
            type: 3,
            required: true,
            choices: [
                {
                    name: 'disable',
                    value: 'off',
                },
                {
                    name: 'enable',
                    value: 'on',
                    choices: [
                        {
                            name: 'channel',
                            description: 'Select channel to send welcome messages to',
                            type: 7,
                            required: true,
                        },
                    ]
                },
            ],
        },
    ],

CodePudding user response:

Those would be an example of a subcommand and need to be indicated as such and will need descriptions in a couple places.

module.exports = {
    name: 'welcomer',
    permissions: 'MANAGE_CHANNELS',
    description: 'Set Where Welcome Messages Get Sent To.',
    options: [{
        name: 'disable',
        description: `'Disable welcomer`, // Added needed description
        type: 1, //converted to subcommmand
    }, {
        name: 'enable',
        description: `'Enable welcomer`, // Added needed description
        type: 1, //converted to subcommmand
        options: [{
            name: 'channel',
            description: 'Select channel to send welcome messages to',
            type: 7,
            required: true,
            channel_types: [0] // allows only text channels to be selected
        }]
    }],
    // run command pick only one of the below two
    // if command.execute()
    async execute(client, interaction, args)
    // if command.run()
    run: async (client, interaction, args) =>
    // command code below here assumes you have the code in your `interactionCreate` listener to set up args
    {
        if (args.disable) {
            // Code to turn off
        } else if (args.enable) {
            const channel = args.channel
            // Code to turn on
        };
    }
}
  • Related