Plugin Metadata
The unique plugin identifier
Human-readable plugin name
Connect Tiny Claw to a Discord bot
Plugin type
Current plugin version
User ID prefix for Discord users (format:
discord:<discord-user-id>)Setup
1. Create a Discord Bot
- Go to the Discord Developer Portal
- Create a new application
- Add a Bot to your application
- Enable Message Content Intent under Privileged Gateway Intents
- Copy the bot token
2. Pair with Tiny Claw
3. Restart Tiny Claw
The agent will automatically restart to connect the bot. Once connected, the bot will:- Respond to all Direct Messages
- Respond to @mentions in guild channels
- Ignore messages from other bots (including itself)
Configuration
Config Keys
Enable/disable the Discord plugin. Set automatically during pairing.
Reference to the secret key storing the bot token. Set automatically to
channel.discord.Secret Keys
Stores the Discord bot token securely in the secrets engine.
Pairing Tools
The plugin provides two tools for managing Discord integration:discord_pair
Pair Tiny Claw with a Discord bot by storing the bot token and enabling the plugin.
Discord bot token from the Developer Portal
discord_unpair
Disconnect the Discord bot and disable the plugin. The bot token remains in secrets for safety.
Parameters: None
Returns: Success message with instructions to restart
Example:
API Methods
start(context: PluginRuntimeContext)
Initializes the Discord bot and connects to Discord servers.
Runtime context providing access to:
enqueue()- Queue messages to the agentagentContext- Agent configurationsecrets- Secrets manager for token retrievalconfigManager- Config manager for settings
- Checks if plugin is enabled via
channels.discord.enabled - Retrieves bot token from secrets
- Creates Discord client with required intents:
- Guilds
- GuildMessages
- MessageContent
- DirectMessages
- Listens for
MessageCreateevents - Routes messages through
context.enqueue(userId, message)
- Only responds to DMs or @mentions
- Ignores bot messages (including self)
- Strips @mention tokens from message content
- Handles Discord’s 2000-character message limit by chunking responses
- Shows typing indicator while processing
sendToUser(userId: string, message: OutboundMessage)
Sends a proactive message to a Discord user.
Discord user ID in format
discord:<discord-user-id>Message object containing:
content- Text content to sendsource- Source of the message (optional)priority- Message priority (optional)
Promise<void>
Throws: Error if client is not connected or user cannot be fetched
Example:
stop()
Gracefully disconnects the Discord bot.
Returns: Promise<void>
Behavior:
- Destroys the Discord client connection
- Cleans up event listeners
- Logs disconnection
getPairingTools(secrets, configManager)
Returns the pairing tools (discord_pair and discord_unpair) for agent integration.
Secrets manager for storing bot token
Config manager for plugin settings
Tool[] - Array of pairing tools
User ID Format
Discord users are identified with a prefixed format to prevent collisions with other channels:discord:123456789012345678
This ensures Discord sessions are isolated from web UI sessions and other channel types.
Usage Examples
User Conversation via DM
User Conversation via @Mention
Owner Pairing Flow
Long Message Chunking
The plugin automatically handles Discord’s 2000-character limit:Dependencies
discord.js^14.0.0 - Discord API client library@tinyclaw/logger- Logging utilities@tinyclaw/types- Type definitions
Gateway Intents Required
The plugin requires these Discord Gateway Intents:- Guilds - Access to guild information
- GuildMessages - Receive guild message events
- MessageContent - Access message content (Privileged Intent)
- DirectMessages - Receive DM events
Error Handling
The plugin includes comprehensive error handling:- Missing Token: Logs warning if enabled but token not found
- API Errors: Catches and logs Discord API errors
- Reply Failures: Attempts to reply with error message, logs if that also fails
- Message Sending: Throws detailed errors if user cannot be reached
Security
- Bot token stored securely in secrets engine (never in config)
- Token never exposed in logs or error messages
- User IDs prefixed to prevent session hijacking across channels
- Owner-only pairing tools protected by authority system