Commands

Basic CommandKit Bot Structure

Here, you will learn the basics of commands in Discord.js, and how we will create them using our CommandKit package.

Firstly, commands are a way of communicating with your bot via the Discord user interface. This tutorial will teach you how to properly create Slash Commands (Application Commands) to run functions.

With commands in CommandKit, you need to use module.exports to make CommandKit aware of the command.

This is the basic structure of a command in CommandKit:

module.exports = {
    data:
    run: ({}) => {}
    options: {}
}

Data

Our data will take either your JSON structure type command, or we can use SlashCommandBuilder to create this for us, easily. Using SlashCommandBuilder is the way I recommend.

To do this, start with requiring SlashCommandBuilder from Discord.js:

const { SlashCommandBuilder } = require('discord.js')

Now with this in our command, we can set our command structure to this:

const { SlashCommandBuilder } = require('discord.ks')

module.exports = {
    data: new SlashCommandBuilder()
    run: ({}) => {}
    options: {}
}

and we can add our Slash Command name, description, and options below the data: new SlashCommandBuilder(), terminating it with a ; at our last object.

Run

run will be executed when the command is ran. This is an arrow function, so the last set of curly braces {} will be where we insert our code (to execute when ran).

In the first set of ({}), we can destructure parts of the command, and in most cases you want to destructure the "interaction". This will make our run line look like run: ({ interaction }) => {}

Options

Here we can change the properties of our command. We can set it to DevOnly, which will only allow specific role id's, user id's, etc.

We can also set the following:

  • Enabled?

  • userPermissions and more.

Last updated