Registering Custom Commands

Kick Bot provides a flexible system to create and register your own custom commands. This guide will show you how to create, test, and register custom commands to extend Kick Bot's functionality.

Command Module Structure

A command module is a JavaScript object with the following structure:

const MyCustomCommand = {
  // Command name (without the ! prefix)
  name: 'commandname',
  
  // Command description (shown in !help)
  description: 'Description of what the command does',
  
  // Command usage example
  usage: '!commandname [arguments]',
  
  // Command handler function
  handler: async ({ username, args, bot, commandManager }) => {
    // Command logic goes here
    return `Response message to send to chat`;
  }
};

Creating Your First Custom Command

Let's create a simple command that returns the current time:

Integrating Custom Commands into Your Project

There are two ways to register your custom commands:

Method 1: Using the enabledCommands Option

  1. Create a directory for your custom commands, e.g., ./commands/

  2. Place your command modules in this directory

  3. Import and register them when creating the bot:

Method 2: Using the Command Manager After Bot Creation

Advanced Command Features

Accessing Bot Services

The command handler receives several useful objects:

Using the Skillful AI Client

You can use the Skillful AI client in your custom commands:

Maintaining Command State

Commands can maintain state between invocations using the setState and getState functions:

Command with Initialization Logic

Some commands need to perform initialization when they're first enabled. Use the init method for this:

Best Practices for Custom Commands

  1. Keep responses concise: Chat messages should be brief and to the point

  2. Add error handling: Always handle potential errors in your commands

  3. Respect rate limits: Avoid making too many external API calls

  4. Include help text: Make the command's usage clear in the description

  5. Clean up resources: If your command uses external resources, clean them up in the cleanup method

Testing Your Custom Commands

Before integrating into your bot, you can test your command handler function independently:

Run the test with node test-command.js.

Next Steps

Now that you know how to create custom commands, explore the Advanced Configuration Options to fine-tune your KickBot instance.

Last updated