Registering Custom Commands
Registering Custom CommandsKick 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
Command Module StructureA 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
Creating Your First Custom CommandLet's create a simple command that returns the current time:
Integrating Custom Commands into Your Project
Integrating Custom Commands into Your ProjectThere are two ways to register your custom commands:
Method 1: Using the enabledCommands Option
Method 1: Using the enabledCommands OptionCreate a directory for your custom commands, e.g.,
./commands/Place your command modules in this directory
Import and register them when creating the bot:
Method 2: Using the Command Manager After Bot Creation
Method 2: Using the Command Manager After Bot CreationAdvanced Command Features
Advanced Command FeaturesAccessing Bot Services
Accessing Bot ServicesThe command handler receives several useful objects:
Using the Skillful AI Client
Using the Skillful AI ClientYou can use the Skillful AI client in your custom commands:
Maintaining Command State
Maintaining Command StateCommands can maintain state between invocations using the setState and getState functions:
Command with Initialization Logic
Command with Initialization LogicSome commands need to perform initialization when they're first enabled. Use the init method for this:
Best Practices for Custom Commands
Best Practices for Custom CommandsKeep responses concise: Chat messages should be brief and to the point
Add error handling: Always handle potential errors in your commands
Respect rate limits: Avoid making too many external API calls
Include help text: Make the command's usage clear in the description
Clean up resources: If your command uses external resources, clean them up in the
cleanupmethod
Testing Your Custom Commands
Testing Your Custom CommandsBefore integrating into your bot, you can test your command handler function independently:
Run the test with node test-command.js.
Next Steps
Next StepsNow that you know how to create custom commands, explore the Advanced Configuration Options to fine-tune your KickBot instance.
Last updated