Skip to main content
Version: 1.2

Chat input commands

CommandKit provides a very simple way to manage your chat input (slash) commands, including registering them to the Discord API, as well as handling their execution.

To create a new chat input command, create a new file in the src/app/commands directory with the name of the command. This guide will create a basic ping command which will respond with "Pong!" when executed.

src/app/commands/ping.ts
import type { CommandData, ChatInputCommand } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: 'Replies with Pong!',
};

export const chatInput: ChatInputCommand = async (ctx) => {
await ctx.interaction.reply('Pong!');
};

Exports explained

command

This is the command data object which defines the shape of your command. This is directly registered to the Discord API everytime your commands are refreshed.

chatInput

This is the main handler function for your chat input command. By exporting this function, CommandKit will know that it's a chat input command and will register and handle it accordingly.

tip

Chat input commands are just one of the command types that CommandKit supports. Learn more about message commands and context menu commands.

Guild-based commands

You can register your chat input command to specific guilds by using the guilds property in the command object which accepts an array of guild IDs.

src/app/commands/ping.ts
import type { CommandData } from 'commandkit';

export const command: CommandData = {
name: 'ping',
description: 'Replies with Pong!',
guilds: ['1055188344188973066'],
};