### List available CommandKit examples with pnpm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Run this command to see a list of all pre-built examples you can use to start your project. ```bash pnpm create commandkit --list-examples ``` -------------------------------- ### List available CommandKit examples with Bun Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Run this command to see a list of all pre-built examples you can use to start your project. ```bash bunx create-commandkit --list-examples ``` -------------------------------- ### CommandKit v0 Manual Setup Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v0 entry point demonstrating manual setup of the CommandKit instance, bot login, and path configurations. ```javascript import { Client, GatewayIntentBits } from 'discord.js'; import { CommandKit } from 'commandkit'; import path from 'path'; const client = new Client({ intents: [ 'Guilds', 'GuildMessages', 'MessageContent', ], }); new CommandKit({ client, commandsPath: path.join(__dirname, 'commands'), eventsPath: path.join(__dirname, 'events'), validationsPath: path.join(__dirname, 'validations'), skipBuiltInValidations: true, bulkRegister: true, }); client.login('YOUR_TOKEN_HERE'); ``` -------------------------------- ### List available CommandKit examples with npm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Run this command to see a list of all pre-built examples you can use to start your project. ```bash npm create commandkit@latest --list-examples ``` -------------------------------- ### List available CommandKit examples with Yarn Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Run this command to see a list of all pre-built examples you can use to start your project. ```bash yarn create commandkit --list-examples ``` -------------------------------- ### Install @commandkit/analytics with Bun Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-analytics Install the analytics package using Bun to get started. ```bash bun add @commandkit/analytics ``` -------------------------------- ### Install @commandkit/analytics with Yarn Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-analytics Install the analytics package using Yarn to get started. ```bash yarn add @commandkit/analytics ``` -------------------------------- ### Install @commandkit/analytics with npm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-analytics Install the analytics package using npm to get started. ```bash npm install @commandkit/analytics ``` -------------------------------- ### Start Development Server (npm) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit development server using npm. ```bash npx commandkit dev ``` -------------------------------- ### Install @commandkit/devtools with Bun Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-devtools Install the devtools plugin using Bun. ```bash bun add @commandkit/devtools ``` -------------------------------- ### Start Development Server (Bun) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit development server using Bun. ```bash bun x commandkit dev ``` -------------------------------- ### Install CommandKit Queue Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-queue Install the core package using npm. ```bash npm install @commandkit/queue ``` -------------------------------- ### Get CommandKit CLI Help (npm) Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command with npm to display all available options and usage examples for the CommandKit CLI. ```bash npm create commandkit@latest --help ``` -------------------------------- ### Start Production Application (npm) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit production application using npm. ```bash npx commandkit start ``` -------------------------------- ### Get CommandKit CLI Help (Bun) Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command with Bun to display all available options and usage examples for the CommandKit CLI. ```bash bunx create-commandkit --help ``` -------------------------------- ### CommandKit Start Method Source: https://commandkit.dev/docs/api-reference/commandkit/classes/command-kit Starts the CommandKit application. An optional token can be provided. ```typescript start(token?: string | false) ``` -------------------------------- ### User onboarding workflow example Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-workflow An example of a multi-step user onboarding workflow. It includes sending messages, assigning roles, and scheduling a follow-up. ```typescript import { sleep } from 'workflow'; import { sendWelcomeMessage } from './steps/send-welcome-message'; import { assignRole } from './steps/assign-role'; import { sendFollowUpMessage } from './steps/send-follow-up-message'; export async function userOnboardingWorkflow(userId: string, guildId: string) { 'use workflow'; await sendWelcomeMessage(userId, guildId); await assignRole(userId, guildId); await sleep('7 days'); await sendFollowUpMessage(userId, guildId); return { userId, status: 'completed' }; } ``` -------------------------------- ### Start Production Application (Bun) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit production application using Bun. ```bash bun x commandkit start ``` -------------------------------- ### Install @commandkit/analytics with pnpm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-analytics Install the analytics package using pnpm to get started. ```bash pnpm add @commandkit/analytics ``` -------------------------------- ### Start a workflow from a CommandKit command Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-workflow Initiate a workflow using the 'start' function from 'workflow/api'. This example starts the 'greetUserWorkflow' when a chat command is invoked. ```typescript import type { CommandData, ChatInputCommand } from 'commandkit'; import { start } from 'workflow/api'; import { greetUserWorkflow } from '@/workflows/greet/greet.workflow'; export const command: CommandData = { name: 'greet', description: 'Greet a user with a workflow', }; export const chatInput: ChatInputCommand = async (ctx) => { await ctx.interaction.reply("I'm going to greet you! :wink:"); await start(greetUserWorkflow, [ctx.interaction.user.id]); }; ``` -------------------------------- ### Get CommandKit CLI Help (Yarn) Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command with Yarn to display all available options and usage examples for the CommandKit CLI. ```bash yarn create commandkit --help ``` -------------------------------- ### Install @commandkit/tasks Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-tasks Install the tasks plugin using npm. ```bash npm install @commandkit/tasks ``` -------------------------------- ### Install @commandkit/cache Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-cache Install the cache package using npm, Yarn, pnpm, or Bun. ```bash npm install @commandkit/cache ``` ```bash yarn add @commandkit/cache ``` ```bash pnpm add @commandkit/cache ``` ```bash bun add @commandkit/cache ``` -------------------------------- ### Get CommandKit CLI Help (pnpm) Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command with pnpm to display all available options and usage examples for the CommandKit CLI. ```bash pnpm create commandkit --help ``` -------------------------------- ### Install CommandKit with Bun Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Use this command to install CommandKit using Bun. ```bash bun add commandkit ``` -------------------------------- ### Start Production Application (Direct Node.js) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit production application by directly executing the Node.js script. ```bash node dist/index.js ``` -------------------------------- ### Start Development Server (pnpm) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit development server using pnpm. ```bash pnpm dlx commandkit dev ``` -------------------------------- ### Install @commandkit/devtools with Yarn Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-devtools Install the devtools plugin using Yarn. ```bash yarn add @commandkit/devtools ``` -------------------------------- ### Bootstrap Production Server Source: https://commandkit.dev/docs/guide/advanced/using-cli-api Starts the production server using the production module. Requires a configuration path. ```typescript import { production } from 'commandkit/cli'; // Start production server const server = await production.bootstrapProductionServer( './commandkit.config.ts', ); ``` -------------------------------- ### Install @commandkit/devtools with pnpm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-devtools Install the devtools plugin using pnpm. ```bash pnpm add @commandkit/devtools ``` -------------------------------- ### Start Development Server (Yarn) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit development server using Yarn. ```bash yarn dlx commandkit dev ``` -------------------------------- ### Start Production Application (pnpm) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit production application using pnpm. ```bash pnpm dlx commandkit start ``` -------------------------------- ### Install @commandkit/ratelimit with Bun Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ratelimit Install the ratelimit plugin using Bun. This command adds the necessary package to your project's dependencies. ```bash bun add @commandkit/ratelimit ``` -------------------------------- ### Install @commandkit/devtools with npm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-devtools Install the devtools plugin using npm. ```bash npm install @commandkit/devtools ``` -------------------------------- ### Start Production Application (Yarn) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Command to start the CommandKit production application using Yarn. ```bash yarn dlx commandkit start ``` -------------------------------- ### Start App in Production (CommandKit CLI) Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Use this command to start the bot in production mode using the CommandKit CLI. It loads environment variables from the .env file. ```bash npx commandkit start ``` -------------------------------- ### Install BullMQ for Production Tasks Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-tasks Install the BullMQ package for distributed task scheduling with Redis. ```bash npm install bullmq ``` -------------------------------- ### Install CommandKit with Yarn Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Use this command to install CommandKit using Yarn. ```bash yarn add commandkit ``` -------------------------------- ### Install @commandkit/ai Plugin Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ai Install the @commandkit/ai plugin using npm, yarn, pnpm, or bun. ```bash npm install @commandkit/ai ``` ```bash yarn add @commandkit/ai ``` ```bash pnpm add @commandkit/ai ``` ```bash bun add @commandkit/ai ``` -------------------------------- ### Install CommandKit with npm Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Use this command to install CommandKit using npm. ```bash npm install commandkit ``` -------------------------------- ### Install CommandKit with pnpm Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Use this command to install CommandKit using pnpm. ```bash pnpm add commandkit ``` -------------------------------- ### Start App in Production (Manual Node.js) Source: https://commandkit.dev/docs/guide/advanced/setup-commandkit-manually Manually start the bot in production mode using Node.js. This command assumes the compiled files are in the 'dist' directory. ```bash node dist/index.js ``` -------------------------------- ### Basic Runtime Plugin Example Source: https://commandkit.dev/docs/guide/creating-plugins/creating-runtime-plugin Create a basic runtime plugin by extending the RuntimePlugin class. This example logs a message when the bot successfully logs in. ```typescript import { type CommandKitPluginRuntime, RuntimePlugin } from 'commandkit'; export class MyRuntimePlugin extends RuntimePlugin { // Override any hooks you want to use async onAfterClientLogin(ctx: CommandKitPluginRuntime): Promise { console.log('Bot has logged in!'); } } ``` -------------------------------- ### Install Google Gemini AI SDK Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ai Install the Google Gemini AI SDK using npm, yarn, pnpm, or bun if you plan to use Google Gemini models. ```bash npm install @ai-sdk/google ``` ```bash yarn add @ai-sdk/google ``` ```bash pnpm add @ai-sdk/google ``` ```bash bun add @ai-sdk/google ``` -------------------------------- ### v1 Project Structure Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of the new v1 project structure featuring an 'app' directory for commands and events. ```treeview . ├── src/ │ ├── app/ │ │ ├── commands/ │ │ │ └── ping.ts │ │ └── events/ │ │ └── clientReady/ │ │ └── log.ts │ └── app.ts ├── .env ├── commandkit.config.ts ├── package.json └── tsconfig.json ``` -------------------------------- ### Install CommandKit Queue with Discord.js and Redis Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-queue Install the necessary packages for Discord.js integration with Redis. ```bash npm install @commandkit/queue @discordjs/brokers ioredis ``` -------------------------------- ### Install @commandkit/ratelimit with npm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ratelimit Install the ratelimit plugin using npm. This is the first step to enable rate limiting in your CommandKit application. ```bash npm install @commandkit/ratelimit ``` -------------------------------- ### v0 Project Structure Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of the legacy v0 project structure. ```treeview . ├── src/ │ ├── commands/ │ │ └── ping.ts │ ├── events/ │ │ └── clientReady/ │ │ └── log.ts │ └── index.ts ├── .env ├── commandkit.config.mjs ├── package.json └── tsconfig.json ``` -------------------------------- ### Task Definition Example Source: https://commandkit.dev/docs/api-reference/tasks/classes/task An example demonstrating how to define a task with a name, schedule, preparation logic, and execution logic. ```APIDOC ## Task Definition Example ### Description This example shows how to create a task using the `task` function. It includes a name, a cron schedule, a `prepare` function to conditionally execute, and an `execute` function for the main task logic. ### Usage ```typescript import { task } from '@commandkit/tasks'; export default task({ name: 'cleanup-old-data', schedule: '0 2 * * *', // Daily at 2 AM async prepare(ctx) { // Only run if there's old data to clean return await hasOldData(); }, async execute(ctx) { await cleanupOldRecords(); await ctx.commandkit.client.channels.cache .get('log-channel')?.send('Cleanup completed!'); }, }); ``` ``` -------------------------------- ### Install @commandkit/ratelimit with Yarn Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ratelimit Install the ratelimit plugin using Yarn. This command adds the necessary package to your project's dependencies. ```bash yarn add @commandkit/ratelimit ``` -------------------------------- ### Install @commandkit/legacy with Bun Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-legacy Install the legacy plugin using Bun. This package is deprecated and only supported up to CommandKit v1.2.0-rc.10. ```bash bun add @commandkit/legacy ``` -------------------------------- ### Creating a StringSelectMenu Source: https://commandkit.dev/docs/api-reference/commandkit/functions/string-select-menu Example of how to create a basic StringSelectMenu with options. Ensure you import StringSelectMenu and StringSelectMenuOption from 'commandkit'. ```typescript import { StringSelectMenu } from 'commandkit'; const stringSelectMenu = ``` -------------------------------- ### Install @commandkit/ratelimit with pnpm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ratelimit Install the ratelimit plugin using pnpm. This command adds the necessary package to your project's dependencies. ```bash pnpm add @commandkit/ratelimit ``` -------------------------------- ### Install @commandkit/i18n with npm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-i18n Install the i18n plugin using npm. This is the first step to enable multilingual support in your CommandKit bot. ```bash npm install @commandkit/i18n ``` -------------------------------- ### Initialize Tasks Plugin Source: https://commandkit.dev/docs/api-reference/tasks/functions/tasks Example of how to import and initialize the tasks plugin with options for task path and HMR. ```typescript import { tasks } from '@commandkit/tasks'; export default { plugins: [ tasks({ tasksPath: 'app/tasks', enableHMR: true, }), ], }; ``` -------------------------------- ### Basic Setup for @commandkit/devtools Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-devtools Add the devtools plugin to your CommandKit configuration to enable its features. ```typescript import { defineConfig } from 'commandkit'; import { devtools } from '@commandkit/devtools'; export default defineConfig({ plugins: [devtools()], }); ``` -------------------------------- ### Use CLI options with Bun Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit These commands demonstrate various CLI options for customizing project setup, such as skipping prompts, specifying package managers, or using custom repositories. ```bash # Skip prompts and use defaults bunx create-commandkit --yes # Use a specific package manager bunx create-commandkit --use-pnpm bunx create-commandkit --use-yarn bunx create-commandkit --use-bun bunx create-commandkit --use-deno ``` -------------------------------- ### Setup @commandkit/cache Plugin Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-cache Add the cache plugin to your CommandKit configuration file. ```typescript import { defineConfig } from 'commandkit'; import { cache } from '@commandkit/cache'; export default defineConfig({ plugins: [cache()], }); ``` -------------------------------- ### Create a basic TypeScript bot with npm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use the `--example basic-ts` flag to create a new project pre-configured with TypeScript. This is useful for projects requiring static typing. ```bash # Create a basic TypeScript bot npm create commandkit@latest --example basic-ts # Create a basic JavaScript bot npm create commandkit@latest --example basic-js # Create a Deno TypeScript bot npm create commandkit@latest --example deno-ts # Create a bot without CLI integration npm create commandkit@latest --example without-cli ``` -------------------------------- ### Create a basic TypeScript bot with Bun Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use the `--example basic-ts` flag to create a new project pre-configured with TypeScript. This is useful for projects requiring static typing. ```bash # Create a basic TypeScript bot bunx create-commandkit --example basic-ts # Create a basic JavaScript bot bunx create-commandkit --example basic-js # Create a Deno TypeScript bot bunx create-commandkit --example deno-ts # Create a bot without CLI integration bunx create-commandkit --example without-cli ``` -------------------------------- ### Create a basic TypeScript bot with pnpm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use the `--example basic-ts` flag to create a new project pre-configured with TypeScript. This is useful for projects requiring static typing. ```bash # Create a basic TypeScript bot pnpm create commandkit --example basic-ts # Create a basic JavaScript bot pnpm create commandkit --example basic-js # Create a Deno TypeScript bot pnpm create commandkit --example deno-ts # Create a bot without CLI integration pnpm create commandkit --example without-cli ``` -------------------------------- ### v0 Command File Structure (TypeScript) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v0 command file in TypeScript, demonstrating the legacy structure. ```typescript import type { CommandData, SlashCommandProps } from 'commandkit'; export const data: CommandData = { name: 'ping', description: 'Pong!', }; export function run({ interaction }: SlashCommandProps) { interaction.reply('Pong!'); } ``` -------------------------------- ### Create a new CommandKit project with npm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command to start an interactive CLI for setting up a new CommandKit project. This is the recommended method for new projects. ```bash npm create commandkit@latest ``` -------------------------------- ### Reminder Command with Dynamic Task Creation Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-tasks Example of a Discord slash command that creates a dynamic reminder task. It parses time input using `ms` and stores relevant data for the task. Ensure `ms` is installed (`npm install ms`). ```typescript import type { CommandData, ChatInputCommand } from 'commandkit'; import { ApplicationCommandOptionType } from 'discord.js'; import ms from 'ms'; import { createTask } from '@commandkit/tasks'; export const command: CommandData = { name: 'remind', description: 'remind command', options: [ { name: 'time', description: 'The time to remind after. Eg: 6h, 10m, 1d', type: ApplicationCommandOptionType.String, required: true, }, { name: 'message', description: 'The message to remind about.', type: ApplicationCommandOptionType.String, required: true, }, ], }; export const chatInput: ChatInputCommand = async (ctx) => { const time = ctx.options.getString('time', true); const message = ctx.options.getString('message', true); const timeMs = Date.now() + ms(time as `${number}`); await createTask({ name: 'remind', data: { userId: ctx.interaction.user.id, message, channelId: ctx.interaction.channelId, setAt: Date.now(), }, schedule: timeMs, }); await ctx.interaction.reply( `I will remind you for `${message} ``, ); }; ``` -------------------------------- ### Use CLI options with npm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit These commands demonstrate various CLI options for customizing project setup, such as skipping prompts, specifying package managers, or using custom repositories. ```bash # Skip prompts and use defaults npm create commandkit@latest --yes # Use a specific package manager npm create commandkit@latest --use-pnpm npm create commandkit@latest --use-yarn npm create commandkit@latest --use-bun npm create commandkit@latest --use-deno # Skip dependency installation npm create commandkit@latest --skip-install # Skip git initialization npm create commandkit@latest --no-git # Create in a specific directory npm create commandkit@latest my-bot # Use a custom GitHub repository npm create commandkit@latest --example "https://github.com/user/repo" ``` -------------------------------- ### Use CLI options with pnpm Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit These commands demonstrate various CLI options for customizing project setup, such as skipping prompts, specifying package managers, or using custom repositories. ```bash # Skip prompts and use defaults pnpm create commandkit --yes # Use a specific package manager pnpm create commandkit --use-pnpm pnpm create commandkit --use-yarn pnpm create commandkit --use-bun pnpm create commandkit --use-deno # Skip dependency installation pnpm create commandkit --skip-install # Skip git initialization pnpm create commandkit --no-git # Create in a specific directory pnpm create commandkit my-bot # Use a custom GitHub repository pnpm create commandkit --example "https://github.com/user/repo" ``` -------------------------------- ### Import and Initialize RoleSelectMenu Source: https://commandkit.dev/docs/api-reference/commandkit/functions/role-select-menu Demonstrates how to import and initialize the RoleSelectMenu component. This is the basic setup required to use the component. ```typescript import { RoleSelectMenu } from 'commandkit'; const roleSelectMenu = ``` -------------------------------- ### Create CommandKit Project with Custom Example Repo Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command to create a new CommandKit project from a custom GitHub repository. ```bash bunx create-commandkit --example "https://github.com/user/repo" ``` -------------------------------- ### Import and Initialize ChannelSelectMenu Source: https://commandkit.dev/docs/api-reference/commandkit/functions/channel-select-menu Import the ChannelSelectMenu component from CommandKit and create an instance. This is the basic setup for using the component. ```typescript import { ChannelSelectMenu } from 'commandkit'; const channelSelectMenu = ``` -------------------------------- ### Example Category Directory Structure Source: https://commandkit.dev/docs/guide/commands/category-directory Illustrates how to organize commands into nested category directories within the src/app/commands folder for logical grouping. ```tree . ├── src/ │ ├── app/ │ │ ├── commands/ │ │ │ ├── (Fun)/ │ │ │ │ ├── (Jokes)/ │ │ │ │ │ ├── random-joke.ts │ │ │ │ │ └── dad-joke.ts │ │ │ │ ├── 8ball.ts │ │ │ │ ├── cat.ts │ │ │ │ └── dog.ts │ │ │ └── (Moderation)/ │ │ │ ├── timeout.ts │ │ │ ├── kick.ts │ │ │ └── ban.ts │ │ └── events/ │ │ └── clientReady/ │ │ └── log.ts │ └── app.ts ├── .env ├── .gitignore ├── commandkit.config.ts ├── package.json └── tsconfig.json ``` -------------------------------- ### Configuring KV Store Options Source: https://commandkit.dev/docs/guide/useful-utilities/commandkit-kv Shows how to create a KV store instance with custom configurations, including specifying a different database file or using an in-memory store for testing. It also demonstrates creating a store with a specific namespace. ```typescript import { openKV } from 'commandkit/kv'; // Create with custom database file const kv = openKV('my-bot-data.db'); // In-memory store for testing const testKv = openKV(':memory:'); // Create with specific namespace const userKv = openKV('data.db', { namespace: 'users', }); ``` -------------------------------- ### Create a basic TypeScript bot with Yarn Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use the `--example basic-ts` flag to create a new project pre-configured with TypeScript. This is useful for projects requiring static typing. ```bash # Create a basic TypeScript bot yarn create commandkit --example basic-ts # Create a basic JavaScript bot yarn create commandkit --example basic-js # Create a Deno TypeScript bot yarn create commandkit --example deno-ts # Create a bot without CLI integration yarn create commandkit --example without-cli ``` -------------------------------- ### Use CLI options with Yarn Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit These commands demonstrate various CLI options for customizing project setup, such as skipping prompts, specifying package managers, or using custom repositories. ```bash # Skip prompts and use defaults yarn create commandkit --yes # Use a specific package manager yarn create commandkit --use-pnpm yarn create commandkit --use-yarn yarn create commandkit --use-bun yarn create commandkit --use-deno # Skip dependency installation yarn create commandkit --skip-install # Skip git initialization yarn create commandkit --no-git # Create in a specific directory yarn create commandkit my-bot # Use a custom GitHub repository yarn create commandkit --example "https://github.com/user/repo" ``` -------------------------------- ### Bootstrap Development Server Source: https://commandkit.dev/docs/guide/advanced/using-cli-api Starts the development server with file watching and HMR using the development module. Requires a configuration path. ```typescript import { development } from 'commandkit/cli'; // Bootstrap development server const devServer = await development.bootstrapDevelopmentServer( './commandkit.config.ts', ); // Access the development server instance const watcher = devServer.watcher; const process = devServer.getProcess(); ``` -------------------------------- ### v0 Validation Example (TypeScript) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v0 validation function in TypeScript that blocks command execution. ```typescript import type { ValidationProps } from 'commandkit'; export default function (ctx: ValidationProps) { if (ctx.interaction.isRepliable()) { ctx.interaction.reply('You are blocked from running the command!'); } return true; // command will not be executed }; ``` -------------------------------- ### Import and Use Container Component Source: https://commandkit.dev/docs/api-reference/commandkit/functions/container Demonstrates how to import and initialize the Container component from the 'commandkit' library. ```typescript import { Container } from 'commandkit'; const container = ...; ``` -------------------------------- ### onApplicationBootstrap Source: https://commandkit.dev/docs/api-reference/commandkit/functions Registers a callback to be executed when the application bootstraps. ```APIDOC ## onApplicationBootstrap ### Description Registers a callback function to be executed once the entire application has successfully bootstrapped. This is useful for initialization tasks that depend on the application being fully set up. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```javascript // Example usage (syntax may vary based on SDK context) onApplicationBootstrap(() => { console.log('Application is fully bootstrapped!'); }); ``` ### Response None explicitly documented. ``` -------------------------------- ### v1 Middleware Example (TypeScript) Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v1 middleware function in TypeScript that blocks command execution. ```typescript import type { MiddlewareContext, stopMiddlewares } from 'commandkit'; export function beforeExecute(ctx: MiddlewareContext) { // Example: Block command execution based on conditions if (ctx.interaction.isRepliable()) { ctx.interaction.reply('Access denied: Command execution blocked.'); } stopMiddlewares(); // Prevents command execution } ``` -------------------------------- ### Channel Select Menu Example Source: https://commandkit.dev/docs/guide/jsx-components/interactive-components/select-menu Creates a channel select menu that allows users to pick a channel from the server. It replies with the selected channel and disposes of the context. ```typescript import { type ChatInputCommand, type OnChannelSelectMenuKitSubmit, ActionRow, ChannelSelectMenu, } from 'commandkit'; import { MessageFlags } from 'discord.js'; const handleSelect: OnChannelSelectMenuKitSubmit = async ( interaction, context, ) => { const channel = interaction.values[0]; await interaction.reply({ content: `Selected channel: <#${channel}>`, flags: MessageFlags.Ephemeral, }); // Clean up the select menu context context.dispose(); }; export const chatInput: ChatInputCommand = async ({ interaction }) => { const selectMenu = ( ); await interaction.reply({ content: 'Select a channel:', components: [selectMenu], }); }; ``` -------------------------------- ### Install @commandkit/legacy with pnpm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-legacy Install the legacy plugin using pnpm. This package is deprecated and only supported up to CommandKit v1.2.0-rc.10. ```bash pnpm add @commandkit/legacy ``` -------------------------------- ### Install @commandkit/legacy with Yarn Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-legacy Install the legacy plugin using Yarn. This package is deprecated and only supported up to CommandKit v1.2.0-rc.10. ```bash yarn add @commandkit/legacy ``` -------------------------------- ### Install @commandkit/legacy with npm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-legacy Install the legacy plugin using npm. This package is deprecated and only supported up to CommandKit v1.2.0-rc.10. ```bash npm install @commandkit/legacy ``` -------------------------------- ### CommandKit v0 Manual Configuration Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v0 configuration file requiring manual specification of src and main entry points. ```javascript import { defineConfig } from 'commandkit'; export default defineConfig({ src: 'src', main: 'index.mjs', // Manual configuration was required }); ``` -------------------------------- ### Install @commandkit/i18n with pnpm Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-i18n Install the i18n plugin using pnpm. This command ensures the package is available for your CommandKit project. ```bash pnpm add @commandkit/i18n ``` -------------------------------- ### Install @commandkit/i18n with Bun Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-i18n Install the i18n plugin using Bun. This command adds the package to your project, enabling i18n capabilities. ```bash bun add @commandkit/i18n ``` -------------------------------- ### Install @commandkit/i18n with Yarn Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-i18n Install the i18n plugin using Yarn. This command adds the necessary package to your project's dependencies. ```bash yarn add @commandkit/i18n ``` -------------------------------- ### Prepare System Prompt for AI Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-ai Customize the AI's behavior and context by preparing a system prompt. This example includes server and channel information, along with guidelines for response length and tone. ```javascript prepareSystemPrompt: async (ctx, message) => { const serverName = message.guild?.name || 'Direct Message'; return `You are ${message.client.user.username}, a helpful Discord bot. **Context:** - Server: ${serverName} - Channel: ${message.channel.name || 'DM'} **Guidelines:** - Keep responses under 2000 characters - Be helpful and friendly - Use available commands when appropriate`; }, ``` -------------------------------- ### Custom Development Server with CLI API Source: https://commandkit.dev/docs/guide/advanced/using-cli-api An example of creating a custom development server using the CommandKit CLI API. This includes setting environment variables, bootstrapping the server, and adding custom file watchers. ```typescript import { development, env } from 'commandkit/cli'; async function customDevServer() { // Set custom environment variables process.env.CUSTOM_DEV_FLAG = 'true'; // Bootstrap development server const devServer = await development.bootstrapDevelopmentServer( './commandkit.config.ts', ); // Add custom file watchers devServer.watcher.on('change', (path) => { console.log(`File changed: ${path}`); // Custom logic here }); // Access the running process const process = devServer.getProcess(); return devServer; } customDevServer(); ``` -------------------------------- ### Create CommandKit Project (Skip Install) Source: https://commandkit.dev/docs/guide/getting-started/setup-commandkit Use this command to create a new CommandKit project without installing dependencies automatically. ```bash bunx create-commandkit --skip-install ``` -------------------------------- ### Get Method with Dot Notation Source: https://commandkit.dev/docs/api-reference/commandkit/classes/kv Illustrates how to retrieve nested properties from a stored object using dot notation with the `get` method. ```typescript // Store an object kv.set('user:123', { name: 'John', age: 30, settings: { theme: 'dark' } }); // Get the entire object const user = kv.get('user:123'); // { name: 'John', age: 30, settings: { theme: 'dark' } } // Get nested properties using dot notation const name = kv.get('user:123.name'); // 'John' const theme = kv.get('user:123.settings.theme'); // 'dark' ``` -------------------------------- ### createSystemPrompt Source: https://commandkit.dev/docs/api-reference/ai/functions Creates a system prompt for AI interaction. ```APIDOC ## createSystemPrompt ### Description Creates a system prompt for AI interaction. ### Method N/A (Function call) ### Endpoint N/A (Function call) ### Parameters N/A ### Request Example N/A ### Response N/A ``` -------------------------------- ### Install @commandkit/workflow and workflow Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-workflow Install the necessary packages using npm. This command adds both the CommandKit workflow plugin and the core workflow library to your project. ```bash npm install @commandkit/workflow workflow ``` -------------------------------- ### CommandKit v1 Simplified Configuration Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a simplified v1 configuration file using defineConfig. Configuration is optional as CommandKit auto-detects the app structure. ```typescript import { defineConfig } from 'commandkit'; export default defineConfig({ // Configuration is now optional for most use cases // CommandKit automatically detects your app structure }); ``` -------------------------------- ### Creating and Configuring a Role Select Menu Source: https://commandkit.dev/docs/api-reference/commandkit/classes/role-select-menu-kit Example of how to instantiate and configure a RoleSelectMenuKit, including setting a filter and an onSelect handler for interactions. ```typescript const modal = new RoleSelectMenuKit() .setTitle('My Modal') .setCustomId('my-modal') .filter((interaction) => interaction.Role.id === '1234567890') .onSelect(async (interaction) => { await interaction.reply('You submitted the modal!'); }) .addComponents(actionRow1, actionRow2); ``` -------------------------------- ### Get Localization Context Source: https://commandkit.dev/docs/api-reference/i18n/functions/locale Usage of the locale function to get the translation context. Call locale() with a locale string to set the context for the returned translation function. ```typescript const { t, locale, i18n } = locale('en-US'); const translated = t('hello'); // Translates 'hello' in the 'en-US' locale ``` -------------------------------- ### Debounce Function Example Source: https://commandkit.dev/docs/api-reference/commandkit/functions/debounce This example demonstrates how to use the debounce function to delay the execution of a function until a specified period of inactivity has passed. Subsequent calls within the delay period will reset the timer. ```typescript const debouncedFn = debounce(() => { console.log('Debounced function called'); }, 300); debouncedFn(); // Will only execute after 300ms of inactivity debouncedFn(); // Will reset the timer debouncedFn(); // Will reset the timer again ``` -------------------------------- ### openKV Source: https://commandkit.dev/docs/api-reference/commandkit/functions Opens a Key-Value store. ```APIDOC ## openKV ### Description Opens a Key-Value (KV) store, providing a persistent or in-memory storage mechanism for key-value pairs. This is useful for caching or storing application state. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```javascript // Example usage (syntax may vary based on SDK context) const kvStore = openKV('myStore'); await kvStore.set('key', 'value'); ``` ### Response None explicitly documented. ``` -------------------------------- ### getCurrentDirectory Source: https://commandkit.dev/docs/api-reference/commandkit/functions Gets the current working directory. ```APIDOC ## getCurrentDirectory ### Description Returns the current working directory of the Node.js process. This is a standard utility function for file system operations. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```javascript // Example usage (syntax may vary based on SDK context) const cwd = getCurrentDirectory(); console.log(`Current directory: ${cwd}`); ``` ### Response None explicitly documented. ``` -------------------------------- ### Creating and Configuring a User Select Menu Source: https://commandkit.dev/docs/api-reference/commandkit/classes/user-select-menu-kit Example of how to instantiate and configure a UserSelectMenuKit, including setting a title, custom ID, filter, and an onSelect handler. ```typescript const modal = new UserSelectMenuKit() .setTitle('My Modal') .setCustomId('my-modal') .filter((interaction) => interaction.user.id === '1234567890') .onSelect(async (interaction) => { await interaction.reply('You submitted the modal!'); }) .addComponents(actionRow1, actionRow2); ``` -------------------------------- ### getTypesFilePath Source: https://commandkit.dev/docs/api-reference/commandkit/functions Gets the file path for type definitions. ```APIDOC ## getTypesFilePath ### Description Returns the file path where type definition files (e.g., `.d.ts`) are located or should be generated. This is relevant for projects using TypeScript or requiring type information. ### Method Not applicable (SDK function) ### Endpoint Not applicable (SDK function) ### Parameters None explicitly documented. ### Request Example ```javascript // Example usage (syntax may vary based on SDK context) const typesPath = getTypesFilePath(); ``` ### Response None explicitly documented. ``` -------------------------------- ### getCurrentNamespace Source: https://commandkit.dev/docs/api-reference/commandkit/classes/kv Gets the name of the currently active namespace. ```APIDOC ## getCurrentNamespace ### Description Gets the name of the currently active namespace. ### Method `getCurrentNamespace() => string` ### Returns * `string` - The name of the current namespace. ``` -------------------------------- ### Organizing Workflows and Steps Source: https://commandkit.dev/docs/guide/official-plugins/commandkit-workflow Illustrates the best practice of keeping workflows focused on orchestration and steps on individual tasks. The 'good' example shows a workflow delegating work to steps, while the 'avoid' example shows an anti-pattern of doing too much work directly in the workflow. ```typescript // Good - workflow orchestrates, steps do work export async function memberVerificationWorkflow( userId: string, guildId: string, ) { 'use workflow'; const member = await fetchMember(userId, guildId); const verified = await verifyMember(member); return { userId, verified, status: 'completed' }; } // Avoid - doing too much in the workflow export async function badWorkflow(userId: string) { 'use workflow'; // Don't do actual work here - use steps instead const user = await fetch('...'); // ❌ } ``` -------------------------------- ### loadConfigFile Source: https://commandkit.dev/docs/api-reference/commandkit/functions/load-config-file Loads the configuration file from the given entrypoint. ```APIDOC ## loadConfigFile ### Description Loads the configuration file from the given entrypoint. ### Signature ```typescript function loadConfigFile(entrypoint: string = COMMANDKIT_CWD): void ``` ### Parameters #### entrypoint - **entrypoint** (string) - Optional - The entrypoint to load the configuration file from. Defaults to COMMANDKIT_CWD. ``` -------------------------------- ### Get Semaphore Storage Source: https://commandkit.dev/docs/api-reference/commandkit/classes/semaphore Retrieves the currently configured storage implementation for the semaphore. ```typescript getStorage() => SemaphoreStorage; ``` -------------------------------- ### CommandKit v1 Streamlined Entry Point Source: https://commandkit.dev/docs/guide/advanced/migrating-from-v0 Example of a v1 entry point where the Discord.js client is exported. CommandKit automatically handles bot login and path configurations. ```typescript import { Client } from 'discord.js'; const client = new Client({ intents: [ 'Guilds', 'GuildMessages', 'MessageContent', ], }); // Optional: Override the default DISCORD_TOKEN env variable client.token = 'CUSTOM_BOT_TOKEN'; export default client; // CommandKit handles the rest automatically ```