Custom slash command arguments

Sometimes you may want to pass in your own options objects to your slash command. This gives you more control over the exact details of your arguments.

typescript
import { ApplicationCommandOptionType } from 'discord.js'
import { CommandObject, CommandType, CommandUsage } from '@nyxb/commands'

export default {
  description: 'Adds numbers together',

  // Create a legacy and slash command
  type: CommandType.BOTH,

  // An array of
  // https://discord.js.org/#/docs/discord.js/main/typedef/ApplicationCommandOption
  options: [
    {
      name: 'num1',
      description: 'The first number',
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
    {
      name: 'num2',
      description: 'The second number',
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
  ],

  callback: (options: CommandUsage) => {
    const { args } = options

    const sum = args.reduce((acc, cur) => {
      return acc + Number(cur)
    }, 0)

    return `The sum is ${sum}`
  },
} as CommandObject
javascript
const { ApplicationCommandOptionType } = require('discord.js')
const { CommandType } = require('@nyxb/commands')

module.exports = {
  description: 'Adds numbers together',

  // Create a legacy and slash command
  type: CommandType.BOTH,

  // An array of
  // https://discord.js.org/#/docs/discord.js/main/typedef/ApplicationCommandOption
  options: [
    {
      name: 'num1',
      description: 'The first number',
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
    {
      name: 'num2',
      description: 'The second number',
      type: ApplicationCommandOptionType.Number,
      required: true,
    },
  ],

  callback: ({ args }) => {
    const sum = args.reduce((acc, cur) => {
      return acc + Number(cur)
    }, 0)

    return `The sum is ${sum}`
  },
}

The options array in this code snippet is similar to what NYXBCommands will auto generate from the code in Inferred slash command arguments.