# Slash commands

Slash commands are a new system for commands within Discord bots. WOKCommands aims to help developers implement slash commands in the easiest way possible.

Here is a basic ping pong slash command example:

{% tabs %}
{% tab title="JavaScript" %}
{% code title="ping.js" %}

```javascript
import { CommandType } from "wokcommands";

export default {
  description: "Ping pong command",

  // Only create a slash command, not a legacy command
  // You can also use "CommandType.BOTH" to create a
  // legacy and slash command
  type: CommandType.SLASH,

  callback: () => {
    return {
      content: "Pong!",
      ephemeral: true,
    };
  },
};
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="ping.ts" %}

```typescript
import { CommandObject, CommandType } from "wokcommands";

export default {
  description: "Ping pong command",

  // Only create a slash command, not a legacy command
  // You can also use "CommandType.BOTH" to create a
  // legacy and slash command
  type: CommandType.SLASH,
  
  callback: () => {
    return {
      content: "Pong!",
      ephemeral: true,
    };
  },
} as CommandObject;
```

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

When running `/ping` it will send "pong" in the same channel.

All of the normal WOKCommands callback arguments are available aside from `message`. A full list can be found [here](https://docs.wornoffkeys.com/commands/commands).

## Using your own Options for Slash Commands

{% embed url="<https://youtu.be/_67r4wq23BA?t=417>" %}

Sometimes you may want to pass in your own options object to your slash command. You can easily do so by passing in an `options` property to your command like so:

{% tabs %}
{% tab title="JavaScript" %}
{% code title="add.js" %}

```javascript
module.exports = {
  category: 'test', // Required for the slash commands
  description: 'Adds two numbers', // Required for the slash commands

  slash: true, // If options are given then slash must be either true or 'both'
  testOnly: true, // Ensure you have test servers setup

  options: [
    {
      name: 'num1', // Must be lower case
      description: 'The first number.',
      required: true,
      type: 'STRING',
    },
    {
      name: 'num2', // Must be lower case
      description: 'The second number.',
      required: true,
      type: 'STRING',
    },
  ],
  callback: ({ interaction, args }) => {
    const num1 = parseInt(args[0])
    const num2 = parseInt(args[1])

    if (interaction) {
      interaction.reply({
        content: String(num1 + num2),
      })
    }
  },
}
```

{% endcode %}
{% endtab %}

{% tab title="TypeScript" %}
{% code title="add.ts" %}

```typescript
```

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


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.wornoffkeys.com/commands/slash-commands.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
