Client Commands
Table of Contents
Before we get started let’s cover the basics.
- aoi.js reads bottom to top, meaning the code starts from the bottom and starts working towards the top.
An example for that is the following:
In this case, the code will send Hello!
first and then Bye!
. This applies to all commands within aoi.js.
Creating Commands
Creating commands brings functionality to your bot, this structure will be used for all commands including events. Events will be covered at a later time.
The structure is as following, (if you’re not using a command handler):
<client>
stands for the AoiClient you defined in your index.js
file at the very top.
Commands have a variety of properties, which will be covered in the next section.
For now you only need to know about name
and code
.
The name
defines the name of the command and also how to execute it. Meaning you would be able to use [prefix]name
to execute the command.
This does nothing, as of now. It’s just a command called ping
. To give it functionality we use the code
property.
The code property defines the functionality of the command - its core.
This would execute upon using the [prefix]ping
within your Discord Server, this would return the current bot latency.
Command Options
There are a variety of commands, event commands, base commands, interaction commands and way more.
Base Commands
The base command, also known as prefix command has a few properties.
An example of using all properties would be the following:
OPTION | INPUT | EXPLANATION |
---|---|---|
name | string | Command Name. |
aliases | string | Aliases, work the same way as name . |
nonPrefixed | boolean | Set your command as non prefixed, meaning it can be executed without the actual prefix. |
dmOnly | boolean | Set the command to be useably only in guilds or Direct Messages. |
executeAt | string | Define where it may can get executed in. 1. guild 2. dm 3. groupDM 4. both |
code | string | Your command code. |
Event Commands
Event commands have the following structure:
<client>
stands - once again - for the AoiClient you defined in your index.js
file at the very top.
<event>
stands for the event you want to use for example onBanAdd
would become <client>.banAddCommand()
. this applies to all commands.
An example of using all properties would be the following:
OPTION | INPUT | EXPLANATION |
---|---|---|
name | string | Command Name. |
type | string | Defines the command type, any event, for example: interaction or loop . |
channel | string | Where the output may go. |
code | string | Your command code. |
Interaction Commands
OPTION | INPUT | EXPLANATION |
---|---|---|
name | string | Command Name. |
type | string | Defines the command type. |
prototype | string | Defines what the command will be triggered by. 1. button 2. selectMenu 4. slash 5. modal |
code | string | Your command code. |
Loop Commands
OPTION | INPUT | EXPLANATION |
---|---|---|
name | string | Command Name. |
type | string | Defines the command type, any event, interaction or loop . |
channel | string | Where the output may go. |
executeOnStartup | boolean | If the command will be executed after the bot restarted. |
every | number | Interval of the loop command. |
code | string | Your command code. |
Command Handler
You can also keep your index.js
- or whatever the file is called for you - neat and tidy, by using command handlers.
By using command handlers, you’re creating a file for each command instead of putting them all in the same file.
Make sure to create a commands folder in the root directory, meaning where your index.js file is located.
- index.js your main file
- package.json
- commands the folder for your commands
- …
Once that is done, we start creating files inside of that folder.
- index.js
- package.json
Directorycommands the folder for your commands
- ping.js
- …
These files can be named what you want, however you need to add the .js
syntax after the name, to turn it into a Javascript file.
Let’s, once again, create a ping command. It’s basically the same, just one line changes.
Everything besides the first line stays the same, easy right?
Your command should look like this in the end:
So let’s look at adding multiple commands to the same file, yes, multiple!
Yet again, we pretty much only change the first and last line.
This is basically an array just with a little extra spice.
Your command should look like this in the end,