Inferred slash command arguments
Slash commands handle arguments differently, however NYXBCommands will allow you to specify your slash command arguments in the same way as normal commands.
typescript
import { CommandObject, CommandType, CommandUsage } from '@nyxb/commands'
export default {
description: 'Adds numbers together',
// Only register a slash command, not a legacy command
type: CommandType.SLASH,
minArgs: 2,
maxArgs: 2,
expectedArgs: '<num1> <num2>',
callback: (options: CommandUsage) => {
const { args } = options
const sum = args.reduce((acc, cur) => {
return acc + Number(cur)
}, 0)
return `The sum is ${sum}`
},
} as CommandObject
Behind the scenes NYXBCommands will create an array of options for your slash commands. As you will see in the next section you can always customize these options if need be.
When using inferred arguments with slash commands, it's very important that you provide minArgs and expectedArgs properties.
CommandsSlash commandsSlash commands are a new system for commands within Discord bots. NYXBCommands aims to help developers implement slash commands in the easiest way possible.
Here is a basic ping pong slash command example:CommandsCustom slash command argumentsSometimes 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.