SLCommands
  • SLCommands Documentation
  • Easy Setup & Options Object
  • SLCommands Class Methods
  • Commands & Contexts
    • Ping command example
    • Command methods
    • Subcommands
  • Events & Features
    • How does features and events work?
    • SLCommands Events
  • Utilities
    • SLCommands Embeds
    • Custom Messages
  • Hope you liked!
Powered by GitBook
On this page
  • Base/Main Command:
  • Sub command:
  1. Commands & Contexts

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:

commands/user.js
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) */
commands/user.ts
import { ChatInputCommand } from '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:

commands/user/info.ts
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!' })
  })
commands/user/info.ts
import { SubCommand } from '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!' })
  })
PreviousCommand methodsNextHow does features and events work?

Last updated 2 years ago