CommandKit Meta-Framework for discord.js

repository·main·Indexed 41 days ago

https://github.com/neplextech/commandkit

A meta-framework for discord.js that simplifies the creation of modular and extensible Discord bots using a file-system based routing approach. It features a unified command structure for slash, prefix, and context menu commands, JSX for declarative Discord UI components, and a suite of specialized packages including @commandkit/ai, @commandkit/analytics, and @commandkit/cache.

Tokens
300.1K
Snippets
1.2K
Records
1.6K
Agent score
51%

What's inside CommandKit

  1. Overview of CommandKit

    main
    CommandKit is a meta-framework for discord.js designed to help developers build powerful, modular, and extensible Discord bots. It provides a structured way to manage commands and integrates with various specialized packages for advanced bot functionality.
  2. Overview of commandkit-plugin-development skill

    main

    The commandkit-plugin-development skill provides the necessary tools and documentation for developers to extend CommandKit by creating custom plugins. It is designed for users who need to hook into the CommandKit lifecycle at either the runtime or compile-time stages.

    Use this skill to accomplish the following tasks:

    • Implement RuntimePlugin hooks to modify behavior during execution.
    • Implement CompilerPlugin transforms to manipulate code during the build process.
    • Extend the commandkit create templates to customize project scaffolding.
    • Wire rolldownPlugins for advanced compile-time customization.
  3. Overview of the commandkit-cache skill

    main
    The commandkit-cache skill provides guidance and implementation patterns for caching architectures using the @commandkit/cache package. It is designed to help developers optimize performance by reducing expensive data fetches and managing data freshness through structured invalidation strategies.
  4. Integrate analytics with CommandKit using PostHog or Umami

    main

    The commandkit-analytics skill provides integration for adding analytics to a CommandKit bot. It supports two primary providers: PostHog and Umami.

    Use this skill to:

    • Add analytics tracking to your bot.
    • Instrument specific command or plugin events.
    • Implement telemetry reduction or no-op operations for specific tasks to respect privacy or reduce noise.
  5. Integrate Redis for distributed coordination with CommandKit

    main

    Use @commandkit/redis to add Redis-backed shared infrastructure to your CommandKit application. This is specifically intended for multi-instance or distributed coordination scenarios where you need to share state across different runtime processes.

    Common use cases include:

    • Caching: Shared cache across multiple instances.
    • Mutex: Distributed locking to prevent race conditions.
    • Semaphore: Distributed concurrency control.
    • Distributed State: Managing state that must be consistent across a cluster.
  6. CommandKit Features Overview

    main

    CommandKit provides several high-level abstractions to simplify Discord bot development:

    • Unified Command Structure: A single file can support slash commands, context menus, and prefix commands.
    • JSX for Discord UI: Write declarative Discord components (Buttons, Modals, Select Menus) using JSX syntax instead of complex discord.js builder chains.
    • Built-in Component Handlers: Define component behavior (e.g., onClick for buttons, onSubmit for modals) directly within the component definition, removing the need for manual InteractionCollector management.
    • Command Middlewares: Implement logic like permission checks, cooldowns, or logging using an Express-like middleware layer that runs before or after command execution.
    • Plugin System: Extend functionality via plugins that hook into the framework lifecycle. Official plugins include @commandkit/i18n (localization) and @commandkit/analytics (usage tracking).
    • Caching: Use the @commandkit/cache plugin to add a caching layer to functions by adding the 'use cache' directive. Supports in-memory and Redis-backed persistence.
    • AI Integration: Use @commandkit/ai to allow users to interact with commands via natural language, powered by the AI SDK (supporting Google Gemini, OpenAI, etc.).
  7. Use the commandkit-redis skill for distributed infrastructure

    main

    The commandkit-redis skill provides the necessary configuration and integration logic for implementing Redis-backed distributed infrastructure within CommandKit ecosystems. Use this skill when your application needs to scale beyond a single process or requires shared state across multiple instances.

    Use cases

    • Scaling: Moving beyond a single process to a multi-instance deployment.
    • State Sharing: Sharing cache, locks, or rate-limit state across different service instances.
    • Integration: Connecting Redis providers with existing CommandKit plugins or utilities.
  8. Agent AI Features Showcase

    main

    The Agent example demonstrates several advanced AI-driven capabilities using CommandKit:

    • Natural Language Commands: Interacting with the bot using everyday language instead of strict command syntax.
    • Natural Language Poll Creation: Creating and managing polls through conversational inputs.
    • AI Image Generation: Generating images from text descriptions via the Clipdrop API.
    • Context-Aware Chatbot: Engaging in natural conversations where the bot maintains context for relevant responses.
    • Channel Management: Effortless creation and management of Discord channels.
  9. Use the commandkit-queue skill for queue architecture

    main

    The commandkit-queue skill is designed to help developers implement queue-based architectures using the @commandkit/queue package. Use this skill when you need to decouple message processing from command execution or implement publish/subscribe workflows for bots.

    Key use cases:

    • Implementing publish/subscribe bot workflows.
    • Configuring queue drivers (such as Redis-backed drivers).
    • Decoupling message processing from command execution to improve system responsiveness and reliability.

    When applying this skill, consider:

    • The producer/consumer flow.
    • Transport and driver constraints.
    • Delivery reliability requirements.
  10. Implement deterministic caching with @commandkit/cache

    main

    Use the @commandkit/cache plugin to implement deterministic caching for read-heavy workloads. This plugin supports 'use cache' directives, cacheTag/cacheLife strategies, and revalidateTag invalidation. You can choose between a memory provider or a Redis provider depending on your deployment topology.

    // Implementation overview:
    // 1. Register cache() plugin
    // 2. Add 'use cache' to deterministic async functions
    // 3. Design tags and TTLs
    // 4. Use revalidateTag for invalidation
  11. Implement scheduled and dynamic jobs with @commandkit/tasks

    main

    The @commandkit/tasks plugin allows you to implement recurring jobs (cron), delayed reminders, and background processing flows. It supports both static task definitions and dynamic task creation using a driver-based architecture.

    Execution Workflow

    To implement tasks correctly, follow these steps:

    1. Register the tasks plugin in your configuration.
    2. Configure and initialize a driver (e.g., Redis or a local driver).
    3. Add static tasks for predefined jobs and implement dynamic creation APIs for jobs created at runtime.
    4. Implement resilience by adding idempotency, error handling, and cancellation support.
  12. Use the commandkit-workflow skill for orchestration

    main

    The commandkit-workflow skill is designed for implementing workflow orchestration patterns using the @commandkit/workflow package. Use this skill when you need to:

    • Implement durable, long-running bot flows.
    • Decompose complex logic into discrete, manageable workflow steps.
    • Wire together a workflow runtime with specific triggers.

    When applying this skill, you should define your target multi-step processes, establish expectations for durability and restarts, and identify integration points with existing commands or events. The goal is to produce a workflow plugin integration, a structured step orchestration, and a reliability-oriented implementation.