Class ChatInputCommand<I>

Represents a command with chat input, aka: a Slash command (/)

Type Parameters

  • I extends ChatInputCommandInteraction = ChatInputCommandInteraction

Hierarchy (view full)

Implements

Constructors

Properties

aliasOf: null | CommandType = null

Represents the command this command is an alias of

aliases: string[] = []

Represents a list of commands that are identical to the original command, with different names

category: null | string = null

This command's category, if omitted, the command's origin file's parent folder name will be parsed and used

Default

'file parent folder name'
client?: Client<boolean>
clientPerms: never[] = []

Permissions required by the client to execute the command

collection?: Collection<string, CommandType>
cooldown: CommandThrottle

Command cooldown/throttling configuration to apply to this command

Note: This is NOT persistent, for that, you should use your own persistent cooldown middleware

Command data to send off to the Discord API, resolved by builder

deferReply: boolean = false

Defers the reply to run interactions internally if possible

disabled: boolean = false

Is the command currently disabled? If so - it won't be available anywhere. Late API updates (users that see the command in their command overview after the API data update) are accounted for

Default

false
global: boolean

Indicates if this command is available globally. If NODE_ENV is production it will default to true. If NODE_ENV is anything else, it will default to false.

guildOnly: boolean = true

Is this command only available in guilds/servers, or also in DMs? You should use InteractionUtils.requireAvailableGuild in your command/controller to assert the interaction type

Default

true
isEphemeral: boolean = false

Tries to (defer, edit, followUp, etc.) reply ephemerally if possible

manager?: CommandManager

Middleware for this command

Example

import { ChatInputMiddlewareFunction } from '../middleware/CommandMiddleware';

const requireDJRole: ChatInputMiddlewareFunction = async ({
next,
client,
command,
interaction,
previousResult,
nextMiddleware,
previousMiddleware,
}) => {
// Do something with available Context
next(); // Only continue to next middleware if next is called
};

export default new ChatInputCommand({
deferReply: true, // You should defer replies ASAP if you're using async middleware
permLevel: PermLevel.Developer,
middleware: [ requireDJRole ],
// OR
middleware: {
preRunChecks: [ requireDJRole ],
// Etc.
}
})
nsfw: boolean = false

Is the command Not Safe For Work? If it is, it will only be available in channels that have the NSFW-flag set enabled

Default

false
permLevel: PermLevel = PermLevel.User

The permission level required to use the command

If higher than or equal to Administrator, data#setDefaultMemberPermissions(0) is automatically called if not explicitly set

Default

PermLevel.User
requiredResourceIds: RequiredResources<I> = ...

Represents a list of required resource IDs for a command

These are used to restrict command usage to specific resources, which is especially useful for private bots/functionality

Every parameter represents a oneOf list of IDs of which AT LEAST ONE is required to match If multiple parameters are provided, all of them must match

Internal permissions and availability/constraint checks still apply

  • guilds: Requires command to be executed in one of the provided guilds
  • channels: Requires command to be executed in one of the provided channels
  • roles: Requires command executor to have one of the provided roles
  • users: Requires command executor to be one of the provided users
  • categories: Requires command channel parent to be one of the provided categories

The function to run when the command is executed

sourceFile: string = DEFAULT_SOURCE_FILE_STRING
sourceFileStackTrace: string = DEFAULT_SOURCE_FILE_STRING
sourceHash: string = DEFAULT_SOURCE_FILE_STRING
userPerms: never[] = []

Permissions required by the user to execute the command

Accessors

Methods

  • Make sure the command matches all constraints - things like required Discord permissions, internal permissions, NSFW channels, etc.

    Parameters

    Returns Promise<boolean>

    True if the command matches all constraints (should execute), false otherwise

  • Convenience method to reply to an interaction and set ephemeral state dynamically - it's nice not having to boilerplate import everywhere

    Parameters

    Returns Promise<null | Message<boolean>>

  • Throttle command usage, make sure we don't exceed the command's configured cooldown

    Parameters

    • interaction: I
    • client: Client<boolean>

    Returns boolean

    Wether or not the command is on cooldown for this interaction