discordjs / builders

A collection of builders that you can use when creating your bot.
Apache License 2.0
97 stars 37 forks source link

Wrong sub/commands types #72

Closed BushEdT closed 2 years ago

BushEdT commented 2 years ago

Issue description

Create new SlashCommandBuilder then .addSubcommand

-> addStringOption returns 1 instead of STRING

It will throws an error :

DiscordAPIError: Invalid Form Body
options[0].type: This field is required

Re-do same thing but with a ApplicationCommandDataResolvable const and it will work as intended :

const command: ApplicationCommandDataResolvable = {
  name: 'test',
  description: 'Test',
  options: [
    {
      name: 'subcommand',
      description: 'Test subcommand',
      type: 'SUB_COMMAND',
      options: [
        {
          name: 'option',
          description: 'Option',
          required: true,
          type: 'STRING',
        },
      ],
    },
  ],
};

Thank you Edward T. Bush

Code sample

const command = new SlashCommandBuilder()
      .setName('test')
      .setDescription('Test')
      .addSubcommand((cmd) =>
        cmd
          .setName('subcommand')
          .setDescription('Test subcommand')
          .addStringOption((option) => option.setName('option').setDescription('Option').setRequired(true))
    );

@discordjs/builders version

0.11.0

Node.js version

v16.13.1

Operating system

Windows 10

Priority this issue should have

Medium (should be fixed soon)

suneettipirneni commented 2 years ago

I tested your code and discord allows me to give that JSON to the API. Option type 1 isn't an error, that's the type for a subcommand, which is what you specified in your builder. The nested options properly show 3 for string.

Test code:

const command = new SlashCommandBuilder()
  .setName('test')
  .setDescription('Test')
  .addSubcommand((cmd) =>
    cmd
      .setName('subcommand')
      .setDescription('Test subcommand')
      .addStringOption((option) =>
        option.setName('option').setDescription('Option').setRequired(true)
      )
  );

(async function main() {
  ...
  client.on('ready', async (readyClient) => {
    const thing = await readyClient.application?.commands.create(
      command.toJSON()
    );
  });
})();
BushEdT commented 2 years ago

I am sorry about that, I didn't have .toJSON() 🤦 It should tell us that it needs it tho...

Thank you !