CommandBuilder class

const command = new CommandBuilder(data?: object);

constructor

The constructor provides one optional argument, which is an object which provides the data for the Command Builder.

The object may contain the following information:

  • name: The name of the command you want to create.

  • description: The description of the command you want to create.

  • options: An array with raw data of the command options which users can fill in in the slash command.

  • nsfw: A boolean which defines whether the command is NSFW or not.

  • dm_permission: Whether the command may be executed in a DM channel.

  • permissions: A bigint which defines a permission the user needs to execute the command, converted to a string.

  • overwrite: Whether to overwrite any existing commands with the same name.

Properties

name

The name of the command which was set with the setName function.

description

The description of the command which was set with the setDescription function.

options

An array with the options converted to an object to make it a valid Discord API object, that have been set with the addOptions function.

dm_permission

A boolean which defines whether the command should be available in the DM channel of the bot or not.

permissions

A permission that has been set with the setPermission function which defines the permission a user needs to execute the command.

nsfw

A boolean which defines whether the command should be marked as NSFW or not, which was set with the setNSFW function.

overwrite

A boolean which defines whether the command should overwrite any other existing commands with the same name, which was set with the setOverwrite function.

Functions

setName

commandBuilder.setName(name: string) : CommandBuilder;

Sets a name for the command and returns the same CommandBuilder class so you don't have to declare it everytime again. This is required to create a command.

setDescription

commandBuilder.setDescription(description: string) : CommandBuilder;

Sets a description for the command and returns the same CommandBuilder class so you don't have to declare it everytime again. This is required to create a command.

setCategory

commandBuilder.setCategory(category: string) : CommandBuilder;

Gives the command a category which will be used to display the command in the help embed. The function returns the same CommandBuilder class so you don't have to declare it everytime again. By not using this function, the command will by default get the General category.

setPermission

commandBuilder.setPermission(permission: permissionsBitfield) : CommandBuilder;

Sets a permission to the command so only users with the set permission can execute the command and returns the same CommandBuilder class so you don't have to declare it everytime again. See the permissionsBitfield page for the available permissions.

setNSFW

commandBuilder.setNSFW(nsfw?: boolean) : CommandBuilder;

Marks or unmarks the command as NSFW and returns the same CommandBuilder class so you don't have to declare it everytime again. If there aren't any arguments provided, the bot will automatically mark the command as NSFW. By setting the nsfw argument to false, it will unmark the command as nsfw.

setOverwrite

commandBuilder.setOverwrite(overwrite?: boolean) : CommandBuilder;

Changes the overwrite status of the command and returns the same CommandBuilder class so you don't have to declare it everytime again. The overwrite argument defines whether the command should overwrite any other existing commands with the same name. If there aren't any arguments provided, the bot will automatically overwrite any existing commands with the same name.

addOptions

commandBuilder.addOptions(...options: [CommandOptionsBuilder]) : CommandBuilder;

Adds options to the command which users can fill in and returns the same CommandBuilder class so you don't have to declare it everytime again. The options will be returned to the addon once the user executes the command.

toJSON

commandBuilder.toJSON() : object;

Converts the CommandBuilder to an object to make it a valid object for the Discord API.

{
    name: string;
    description: string;
    options?: [object];
    dm_permission: boolean;
    default_member_permission?: string;
    nsfw: boolean;
    overwrite: boolean;
}

Last updated