Subcommands
Subcommands are a little different. They need the reference
property and their options are located in the base command. Here is an example:
Note: you can handle the subcommands in the main command if you do not create the SLSubCommand.
Do not forget: onExecute
or addSubCommand
must be the last functions, so the command is properly registered.
Base/Main Command:
const { ChatInputCommand } = require('sl-commands')
new ChatInputCommand()
/** The command name (required) */
.setName('ping')
/** The command description (required) */
.setDescription('Shows my ping')
/** If only bot developers will be able to use the command */
.setDevsOnly(true)
/** Whether the command will be only registered in test servers or not */
.setTestOnly(true)
/** The required server permissions for using the command */
.setRequiredPermissions('Administrator')
/** There's a lot of types of options, this is one example of how to add one boolean option */
.addSubcommand(option => option.setName('show').setDescription('Testing'))
/** onExecute not required (useless) */
Sub command:
const { SubCommand } = require('sl-commands')
new SubCommand()
// The subcommand name (the same you provided in the main command)
.setName('show')
// The main command name
.setReference('ping')
// This will be the same as Chat Input command function
.onExecute(({ client, interaction }) => {
interaction.reply({ content: 'Shown!' })
})
Last updated