Skip to content

Setting up Prefix Commands

Follow the folder structure and create sub folders inside your command folder. Name these sub-folders as a category name for your command files. In order for commands to run when placed inside their respective sub-folders of the command folder, you need to set the properties for each command.

Here is a sample command example with the filename of "ping.js" and it's the command properties:

module.exports = {
    name: 'ping',  //name of command when using <prefix>ping
    description: 'Ping Pong Command!', // description of command
    /**
     * Defines what the prefix command does, 
     * 
     * note for v3.1.0 or later:
     * execute property has backward compatibility to run prefix commands
     */
    executePrefix(message, args, client) {
        return message.channel.send({ content: 'Pong.'});
    },
};

name string
This is the command name

description string
This is the description of the command and its functionality

aliases Array<String>
This is the different abbreviation (aliases) of the command that you can use to call and execute the command

guildOnly boolean = false
This is set the command if it can only be used within a server or can be used within direct message with the bot

permissions number = 0
This is the permission level value of who can execute the command. If set to 0, any user can run this command, 5 is the server owner and 10 is only the bot owner can run the command. For more details, please refer to the config file on the permission levels.

minArgs number = 0
This is the minimum arguments required to execute the command

maxArgs number
This is the maximum arguments required to execute the command

customIds Array<String>
An Array of strings containing strings of customIds used in current command file.

usage string
Show by writing an example of how to execute the command using the command argument(s) in the command call Example: !ping

executePrefix(message, args, client, level) Promise<Message>
This is a function that is invoked when the prefix command is called to be executed.

Original execute property in v3.1.0 or later

If both the interactionReply and data properties are defined for the same command, the execute property will still run prefix commands. This behavior is provided for backward compatibility and will be removed in v4.0.0.

However, if the data property is defined and the interactionReply property is not, the execute property will run as a slash command instead. In this case, executePrefix is required for prefix commands. This will be the expected behavior from v4.0.0 and later.

Property Type Required Description
message Message Class true This is the message object that represents a message on Discord.
args Array<string> false This is the arguments array that is required and sent by the user when the command gets executed.
client Discord.Client false This is the Discord client object.
level Number false This is the user's permission level.