> For the complete documentation index, see [llms.txt](https://ephf.gitbook.io/discord-short/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://ephf.gitbook.io/discord-short/creating-bot-commands/slash-commands.md).

# Slash Commands

Discord.Short allows an easier method of creating slash commands!

When writing a slash command, its very similar to a normal command.

Lets start by creating a slash command, this is what one would normally look like:

```javascript
new ds.Command({
    name: 'help',
    description: 'Need Help?', // required in a slash command
    slash: true, // making this command into a slash command
    guild: '839993561280938035', // optional
    async execute({arguments}) {
        // args
    }
});
```

where you see `arguments`, you can add any of these arguments:

* `interaction` - the actual interaction coming from the command
* `channel` - the channel the command was used in
* `guild` - the server the command was used in
* `author` - the user who used the command
* `args[]` - the arguments after the command
* `send()` - sending a message in the channel where the command was executed

so lets add a reply, ill be requiring `MessageEmbed` from `discord.js`

```javascript
const { MessageEmbed } = Discord;

new ds.Command({
    name: 'help',
    description: 'Need Help?',
    setSlash: true,
    guild: '839993561280938035',
    async execute({send, author}) {
        send('Showing Help Embed:');
        send(new MessageEmbed({
            title: `Hi, ${author.username}`,
            description: 'This is an example bot for discord.short, an npm package\n> [[Package Link]](https://www.npmjs.com/package/discord.short)',
            footer: {
                text: 'Downloading Discord.Short will make it easier to make discord bots, like this one!'
            },
            color: 'BLUE'
        }));
    }
});

// you can't use MessageEmbeds in slash command replies
```

Overall, the file will look something like this:

{% code title="example.js" %}

```javascript
const Discord = require('discord.short');
const ds = new Discord.Client('example');

const { MessageEmbed } = Discord;

ds.login({
  "botToken": "token",
  "mongo": {
    "username": "ephf",
    "password": "password",
    "cluster": "example.example"
    "database": "example"
  },
  "heroku": {
    "name": "example"
  }
});

new ds.Command({
    name: 'help',
    description: 'Need Help?',
    slash: true,
    guild: '839993561280938035',
    async execute({send, author}) {
        send('Showing Help Embed:');
        send(new MessageEmbed({
            title: `Hi, ${author.username}`,
            description: 'This is an example bot for discord.short, an npm package\n> [[Package Link]](https://www.npmjs.com/package/discord.short)',
            footer: {
                text: 'Downloading Discord.Short will make it easier to make discord bots, like this one!'
            },
            color: 'BLUE'
        }));
    }
});
```

{% endcode %}

again, we can run the bot using `node`

```bash
$ node example.js
```

now, you can see the command on the `/` list:

![in discord](https://1070540812-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_6wR-SQ66c91BUYwWE%2F-M_8aLWgFXp-wPgA-xss%2F-M_8k4BpSxI1p-y7hGn1%2Fhelpslashcommand.png?alt=media\&token=823f5bda-b88b-4f4a-807c-3ad86eb4d7e6)

and when we run it, we get this:

![in discord](https://1070540812-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_6wR-SQ66c91BUYwWE%2F-M_8aLWgFXp-wPgA-xss%2F-M_8l204ROumjvgJ4cR0%2Fhelpembedreply.png?alt=media\&token=68c63689-d9af-411d-a0f2-44e78dd92fa9)

Just like when you create normal commands, you can use arguments. But this is a bit different and required two more parameters:

```javascript
new ds.Command({
    name: 'add1',
    description: 'Add 1 to any number!',
    slash: true,
    guild: '839993561280938035',
    arguments: [
        {
            name: 'number',
            description: 'the number you are adding 1 to',
            required: true,
            type: 'number'
        }
    ],
    async execute({send, args}) {
        send(`Answer: ${args[0] + 1}`);
    }
});
```

Then, when we run this in discord, we will get this:

![](https://1070540812-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_6wR-SQ66c91BUYwWE%2F-MaZta1qM0fagbOR5sYr%2F-MaZy2OQk_1hiyvOfRuB%2Fimage.png?alt=media\&token=f13a3490-1e60-48d6-b8e0-dfe73a436601)

![in discord](https://1070540812-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M_6wR-SQ66c91BUYwWE%2F-MaZta1qM0fagbOR5sYr%2F-MaZyB3-Pgd2txYoYX1w%2Fimage.png?alt=media\&token=4dd5119b-0000-4e22-bbc6-8870e073515a)

{% hint style="info" %}
You can set a command to a slash command and a normal command by changing the `slash` parameter to be `"both"`

```javascript
new ds.Command({
    name: 'ping',
    description: 'ping pong',
    slash: "both",
    execute({send}){
        send('Pong!');
    }
});
```

{% endhint %}
