Full source for the-third-rev: Discord bot (discord.py), FastAPI web UI (React/TS/Vite/Tailwind), ComfyUI integration, generation history DB, preset manager, workflow inspector, and all supporting modules. Excluded from tracking: .env, invite_tokens.json, *.db (SQLite), current-workflow-changes.json, user_settings/, presets/, logs/, web-static/ (build output), frontend/node_modules/. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Discord ComfyUI Bot
A Discord bot that integrates with ComfyUI to generate AI images and videos through Discord commands.
Features
- 🎨 Image Generation - Generate images using simple prompts or complex workflows
- 🎬 Video Generation - Support for video output workflows
- 📝 Workflow Management - Load, modify, and execute ComfyUI workflows
- 📤 Image Upload - Upload reference images directly through Discord
- 📊 Generation History - Track and retrieve past generations
- ⚙️ Runtime Workflow Modification - Change prompts, negative prompts, and input images on the fly
- 🔄 Job Queue System - Sequential execution prevents server overload
Quick Start
Prerequisites
- Python 3.9+
- Discord Bot Token (create one here)
- ComfyUI Server running and accessible
- Required packages:
discord.py,aiohttp,websockets,python-dotenv
Installation
-
Clone or download this repository
-
Install dependencies:
pip install discord.py aiohttp websockets python-dotenv -
Create
.envfile with your credentials:DISCORD_BOT_TOKEN=your_discord_bot_token_here COMFY_SERVER=localhost:8188 -
Run the bot:
python bot.py
Configuration
Create a .env file in the project root:
# Required
DISCORD_BOT_TOKEN=your_discord_bot_token
COMFY_SERVER=localhost:8188
# Optional
WORKFLOW_FILE=wan2.2-fast.json
COMFY_HISTORY_LIMIT=10
COMFY_OUTPUT_PATH=C:\Users\YourName\Documents\ComfyUI\output
Configuration Options
| Variable | Required | Default | Description |
|---|---|---|---|
DISCORD_BOT_TOKEN |
✅ Yes | - | Discord bot authentication token |
COMFY_SERVER |
✅ Yes | - | ComfyUI server address (host:port) |
WORKFLOW_FILE |
❌ No | - | Path to workflow JSON to load at startup |
COMFY_HISTORY_LIMIT |
❌ No | 10 |
Number of generations to keep in history |
COMFY_OUTPUT_PATH |
❌ No | C:\Users\...\ComfyUI\output |
Path to ComfyUI output directory |
Usage
All commands use the ttr! prefix.
Basic Commands
# Test if bot is working
ttr!test
# Generate an image with a prompt
ttr!generate prompt:a beautiful sunset over mountains
# Generate with negative prompt
ttr!generate prompt:a cat negative_prompt:blurry, low quality
# Execute loaded workflow
ttr!workflow-gen
# Queue multiple workflow runs
ttr!workflow-gen queue:5
Workflow Management
# Load a workflow from file
ttr!workflow-load path/to/workflow.json
# Or attach a JSON file to the message:
ttr!workflow-load
[Attach: my_workflow.json]
# View current workflow changes
ttr!get-current-workflow-changes type:all
# Set workflow parameters
ttr!set-current-workflow-changes type:prompt A new prompt
ttr!set-current-workflow-changes type:negative_prompt blurry
ttr!set-current-workflow-changes type:input_image input/image.png
Image Upload
# Upload images to ComfyUI
ttr!upload
[Attach: image1.png, image2.png]
# Upload to specific folder
ttr!upload type:temp
[Attach: reference.png]
History
# View recent generations
ttr!history
# Retrieve images from a past generation
ttr!get-history <prompt_id>
ttr!get-history 1 # By index
Command Aliases
Many commands have shorter aliases:
ttr!generate→ttr!genttr!workflow-gen→ttr!wfgttr!workflow-load→ttr!wflttr!get-history→ttr!ghttr!get-current-workflow-changes→ttr!gcwcttr!set-current-workflow-changes→ttr!scwc
Architecture
The bot is organized into focused, maintainable modules:
the-third-rev/
├── config.py # Configuration and constants
├── job_queue.py # Job queue system
├── workflow_manager.py # Workflow manipulation
├── workflow_state.py # Runtime state management
├── discord_utils.py # Discord utilities
├── bot.py # Main entry point (~150 lines)
├── comfy_client.py # ComfyUI API client (~650 lines)
└── commands/ # Command handlers
├── generation.py # Image/video generation
├── workflow.py # Workflow management
├── upload.py # File uploads
├── history.py # History retrieval
└── workflow_changes.py # State management
Key Design Principles
- Dependency Injection - Dependencies passed via constructor
- Single Responsibility - Each module has one clear purpose
- Configuration Centralization - All config in
config.py - Command Separation - Commands grouped by functionality
- Type Safety - Modern Python type hints throughout
Development
Adding a New Command
See QUICK_START.md for quick examples or DEVELOPMENT.md for comprehensive guide.
Basic example:
# commands/your_module.py
def setup_your_commands(bot, config):
@bot.command(name="hello")
async def hello(ctx):
await ctx.reply("Hello!", mention_author=False)
Register in commands/__init__.py:
from .your_module import setup_your_commands
def register_all_commands(bot, config):
# ... existing ...
setup_your_commands(bot, config)
Documentation
- README.md (this file) - Project overview and setup
- QUICK_START.md - Quick reference for common tasks
- DEVELOPMENT.md - Comprehensive development guide
- CLAUDE.md - Architecture documentation for Claude Code
Workflow System
The bot supports two generation modes:
1. Prompt Mode (Simple)
Uses a workflow template with a KSampler node:
ttr!generate prompt:a cat negative_prompt:blurry
The bot automatically finds and replaces:
- Positive prompt in CLIPTextEncode node (title: "Positive Prompt")
- Negative prompt in CLIPTextEncode node (title: "Negative Prompt")
- Seed values (randomized each run)
2. Workflow Mode (Advanced)
Execute full workflow with runtime modifications:
# Set workflow parameters
ttr!set-current-workflow-changes type:prompt A beautiful landscape
ttr!set-current-workflow-changes type:input_image input/reference.png
# Execute workflow
ttr!workflow-gen
The bot:
- Loads the workflow template
- Applies runtime changes from WorkflowStateManager
- Randomizes seeds
- Executes on ComfyUI server
- Returns images/videos
Node Naming Conventions
For workflows to work with dynamic updates, nodes must follow naming conventions:
- Positive Prompt: CLIPTextEncode node with title containing "Positive Prompt"
- Negative Prompt: CLIPTextEncode node with title containing "Negative Prompt"
- Input Image: LoadImage node (any title)
- Seeds: Any node with
inputs.seedorinputs.noise_seed
Troubleshooting
Bot won't start
Issue: AttributeError: module 'queue' has no attribute 'SimpleQueue'
Solution: This was fixed by renaming queue.py to job_queue.py. Make sure you're using the latest version.
ComfyUI connection issues
Issue: ComfyUI client is not configured
Solution:
- Check
.envfile hasDISCORD_BOT_TOKENandCOMFY_SERVER - Verify ComfyUI server is running
- Test connection:
curl http://localhost:8188
Commands not responding
Issue: Bot online but commands don't work
Solution:
- Check bot has Message Content Intent enabled in Discord Developer Portal
- Verify bot has permissions in Discord server
- Check console logs for errors
Video files not found
Issue: Failed to read video file
Solution:
- Set
COMFY_OUTPUT_PATHin.envto your ComfyUI output directory - Check path uses correct format for your OS
Advanced Usage
Batch Generation
Queue multiple workflow runs:
ttr!workflow-gen queue:10
Each run uses randomized seeds for variation.
Custom Workflows
- Design workflow in ComfyUI
- Export as API format (Save → API Format)
- Load in bot:
ttr!workflow-load path/to/workflow.json - Modify at runtime:
ttr!set-current-workflow-changes type:prompt My prompt ttr!workflow-gen
State Persistence
Workflow changes are automatically saved to current-workflow-changes.json and persist across bot restarts.
Contributing
We welcome contributions! Please:
- Read
DEVELOPMENT.mdfor coding guidelines - Follow existing code style and patterns
- Test your changes thoroughly
- Update documentation as needed
License
[Your License Here]
Support
For issues or questions:
- Check the troubleshooting section above
- Review
DEVELOPMENT.mdfor implementation details - Check ComfyUI documentation for workflow issues
- Open an issue on GitHub
Credits
Built with:
- discord.py - Discord API wrapper
- ComfyUI - Stable Diffusion GUI
- aiohttp - Async HTTP client
- websockets - WebSocket implementation