# Command methods

All commands are exported as objects which have properties to dictate how commands will work. Here is a complete list of all available methods:

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

### Chat Input Command (Slash Command)

{% tabs %}
{% tab title="JavaScript" %}
```javascript
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)
  /** There's a lot of types of options, this is one example of how to add one boolean option */
  .addBooleanOption(option =>
    option
      .setName('ephemeral')
      .setDescription('If the reply must be ephemeral')
      .setRequired(true)
  )
  /** The required server permissions for using the command */
  .setRequiredPermissions('Administrator')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The slash command interaction */
      options, /** The options resolver for the command */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(`Pong! ${user}`)
    }
  )
```
{% endtab %}

{% tab title="TypeScript" %}
```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)
  /** There's a lot of types of options, this is one example of how to add one boolean option */
  .addBooleanOption(option =>
    option
      .setName('ephemeral')
      .setDescription('If the reply must be ephemeral')
      .setRequired(true)
  )
  /** The required server permissions for using the command */
  .setRequiredPermissions('Administrator')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The slash command interaction */
      options, /** The options resolver for the command */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(`Pong! ${user}`)
    }
  )
```
{% endtab %}
{% endtabs %}

### Message Context Menu (Right-click messages)

{% tabs %}
{% tab title="JavaScript" %}
```javascript
const { SLMessageCommand } = require('sl-commands')

new SLMessageCommand()
  /** The command name (required) */
  .setName('Content')
  /** 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('ManageMessages', 'ViewChannel')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The context menu interaction */
      target, /** The message which was selected by the user */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(target.content)
    }
  )
```
{% endtab %}

{% tab title="TypeScript" %}
```typescript
import { SLMessageCommand } from 'sl-commands'

new SLMessageCommand()
  /** The command name (required) */
  .setName('Content')
  /** 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('ManageMessages', 'ViewChannel')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction, /** The context menu interaction */
      target, /** The message which was selected by the user */
      handler, /** The SLHandler instance */
      channel, /** The channel where the command has been used */
      client, /** Your Discord Bot client */
      locale, /** The locale from the user who used the command */
      member, /** The member who used the command (might be undefined if used in a DM Channel) */
      guild, /** The guild where the command has been used (might be undefined if used in a DM Channel) */
      user, /** The user who used the command */
    }) => {
      interaction.reply(target.content)
    }
  )
```
{% endtab %}
{% endtabs %}

### User Context Menu (Right-click users)

{% tabs %}
{% tab title="JavaScript" %}
```javascript
const { SLUserCommand } = require('sl-commands')

new SLUserCommand()
  /** The command name (required) */
  .setName('Username')
  /** 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('ManageNicknames')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction /** The context menu interaction */,
      target /** The member who was selected by the user */,
      handler /** The SLHandler instance */,
      client /** Your Discord Bot client */,
      locale /** The locale from the user who used the command */,
      member /** The member who used the command (might be undefined if used in a DM Channel) */,
      guild /** The guild where the command has been used (might be undefined if used in a DM Channel) */,
      user /** The user who used the command */,
    }) => {
      interaction.reply(target.user.username)
    }
  )
```
{% endtab %}

{% tab title="TypeScript" %}
```typescript
import { SLUserCommand } from 'sl-commands'

new SLUserCommand()
  /** The command name (required) */
  .setName('Username')
  /** 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('ManageNicknames')
  /** This will be executed whenever the command is used by someone */
  .onExecute(
    ({
      interaction /** The context menu interaction */,
      target /** The member who was selected by the user */,
      handler /** The SLHandler instance */,
      client /** Your Discord Bot client */,
      locale /** The locale from the user who used the command */,
      member /** The member who used the command (might be undefined if used in a DM Channel) */,
      guild /** The guild where the command has been used (might be undefined if used in a DM Channel) */,
      user /** The user who used the command */,
    }) => {
      interaction.reply(target.user.username)
    }
  )
```
{% endtab %}
{% endtabs %}
