# Normal Commands

To make a normal command, we create something like this:

```javascript
new ds.Command({    
    name: 'ping', // name of command    
    aliases: ['p'], // other names that can be used    
    async execute({arguments}) { // function that runs when the command is used *MUST BE ASYNC*        
        // args    
    }
});
```

where you see `arguments`, you can add any of the following:

* `message` - the message sent
* `author` - the user who sent the message
* `channel`- the channel the message was sent in
* `guild`- the server the message was sent in
* `send()`- a function to send a message in the channel that the message was in
* `args[]`- the arguments (split by a space) after the command
* `label`- the command they used (shows which alias / name they used)

so lets finish the ping command, and add which alias they used:

```javascript
new ds.Command({
    name: 'ping',    
    aliases: ['p'],    
    async execute({send, label}) { // getting "send" and "label"
        send(`Pong! (${label})`);    
    }
});
```

overall the file should look like this:

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

```javascript
const Discord = require('discord.short');
const ds = new Discord.ShortClient('example');
​
ds.login(
{  
    "botToken": "token",
    "mongo": {    ]
        "username": "ephf",    
        "password": "password",    
        "database": "example"  
    },  
    "heroku": {    
        "name": "example"  
    }
});​

ds.setPrefix('!');

new ds.Command({
    name: 'ping',    
    aliases: ['p'],    
    async execute({send, label}) {
        send(`Pong! (${label})`);    
    }
});
```

{% endcode %}

we can then run the bot using `node`

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

and now if you go to your discord server, and type `!ping` you will get this:

![in discord](https://gblobscdn.gitbook.com/assets%2F-M_6wR-SQ66c91BUYwWE%2F-M_6wXrfJegiHbqrlOFJ%2F-M_71aFsxXQvxWINhvmM%2Fdis-ping.png?alt=media\&token=80baff79-61bc-4e17-86ac-1660b6040fa3)

then if you type `!p` you will get this:

![in discord](https://gblobscdn.gitbook.com/assets%2F-M_6wR-SQ66c91BUYwWE%2F-M_6wXrfJegiHbqrlOFJ%2F-M_71jIOC_iSb-TY-zNA%2Fdis-p.png?alt=media\&token=9c768936-b249-4451-996a-b51564c8e7ad)

You can also check if people have permissions, all you need to do is add the `permissions` variable:

```javascript
new ds.Command({
    name: 'amianadmin',    
    aliases: ['aiaa'],
    permissions: ['ADMINISTRATOR'],    
    async execute({send}) {
        send('you are an admin!');    
    }
});
```

since I am an admin in my server, it will display the text "you are an admin!":

![in discord](/files/-M_vQmq7ebcDeNw-DFrN)

we can also add a function to run if the person doesn't have the needed permissions:

```javascript
new ds.Command({
    name: 'amianadmin',    
    aliases: ['aiaa'],
    permissions: ['ADMINISTRATOR'],    
    async execute({send}) {
        send('you are an admin!');    
    },
    async faledPermissions({send}) {
        send('you are not an admin!');
    }
});
```

so if someone without admin permissions run this command, they will get this:

![in discord](/files/-M_vRMSCy4rRlaOS3QMm)

In the failed permissions function, you can get any of the arguments that you can use in the execute function plus these:

* `permissions[]` - the permissions that the sender didn't have

Although this feature is mostly for slash commands, you can use it on normal commands too. If you want, you can add certain arguments that a command needs to follow, like this:

```javascript
new ds.Command({
    name: 'add1',
    arguments: [
        {
            type: 'number',
            required: true
        }
    ],
    execute({send, args}) {
        send(args[0] + 1);
    }
});
```

When you run the command, you will get this:

![in discord](/files/-MaZsrfLZmVmQzQGU7EX)

Whenever you specify an argument type, it will change the argument to that value. If the argument fails the transformation, a different function will be called:

```javascript
new ds.Command({
    name: 'add1',
    arguments: [
        {
            type: 'number',
            required: true
        }
    ],
    execute({send, args}) {
        send(args[0] + 1);
    },
    failedArguments({send}) { // here
        send('That\'s not a number!');
    }
});
```

Now when we run it in discord, it will do this (if the second argument is not a number):

![in discord](/files/-MaZtg47zEThL1ADLlrF)

The argument type can be any of these:

* `any`
* `string`
* `number`
* `boolean`
* `user` (user mention)
* `channel` (channel mention)
* `role` (role mention)
* `mention` (role or user mention)

In the failed arguments function, you can get any of the arguments that you can use in the execute function plus these:

* `argument` - incorrect argument
* `type` - the way it failed
* `number` - which argument failed (starting from 0)

There are three ways an argument can fail. "missing", "incorrect", and "notfound"

* `missing` - the argument parameter `required` was set to `true` and the argument wasn't in the command
* `incorrect` - the argument was the wrong type
* `notfound` - if the argument was some kind of mention, and the bot couldn't find the user / role / channel

We can use the `type` parameter like this:

```javascript
new ds.Command({
    name: 'add1',
    arguments: [
        {
            type: 'number',
            required: true
        }
    ],
    execute({send, args}) {
        send(args[0] + 1);
    },
    failedArguments({send, type}) {
        if(type == 'missing') {
            send('You are missing the first argument!');
        } else {
            send('That\'s not a number!');
        }
    }
});
```

Then if we run the command in discord:

![in discord](/files/-MaZw07Q96SWRFb2DrLi)

Another feature with commands is adding cooldowns. You can add them like this:

```javascript
new ds.Command({
    name: 'ping',
    aliases: ['p'],
    cooldown: 10, // here
    execute({send}) {
        send('Pong!');
    }
});
```

every value of `cooldown` is 1 second. You can also add a `failedCooldown`

```javascript
new ds.Command({
    name: 'ping',
    aliases: ['p'],
    cooldown: 10,
    execute({send}) {
        send('Pong!');
    },
    failedCooldown({send, timeleft}) {
        send(`Wait for another \`${timeleft}s\`!`);
    }
});
```

Then we get this:

![in discord](/files/-Mae7hij1iaICKjhh4Jo)


---

# 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://ephf.gitbook.io/discord-short/creating-bot-commands/normal-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.
