# 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.

{% hint style="warning" %}
Do not forget: `onExecute` or  `addSubCommand` must be the last functions, so the command is properly registered.
{% endhint %}

### Base/Main Command:

{% tabs %}
{% tab title="JavaScript" %}

<pre class="language-javascript" data-title="commands/user.js"><code class="lang-javascript">const { ChatInputCommand } = require('sl-commands')

new ChatInputCommand()
  /** The command name (required) */
  .setName('ping')
  /** The command description (required) */
  .setDescription('Shows my ping')
<strong>  /** If only bot developers will be able to use the command */
</strong>  .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) */
</code></pre>

{% endtab %}

{% tab title="TypeScript" %}
{% code title="commands/user.ts" %}

```typescript
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) */
```

{% endcode %}
{% endtab %}
{% endtabs %}

### Sub command:

{% tabs %}
{% tab title="JavaScript" %}
{% code title="commands/user/info.ts" %}

```javascript
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!' })
  })
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="commands/user/info.ts" %}

```typescript
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!' })
  })
```

{% endcode %}
{% endtab %}
{% endtabs %}
