A Discord bot that combines AI models (Anthropic Claude, OpenAI GPT, and Meta Llama via Cloudflare Workers AI) with channel-based document search, built entirely on Cloudflare's edge platform. Share knowledge within Discord channels with role-based access control - if you can see the channel, you can access its AI and documents.
Imagine you're at a client meeting. They ask about specific terms in a contract you uploaded months ago. Instead of awkwardly searching through emails or saying "I'll get back to you," you simply pull out your phone, open Discord, and type:
#docs What are the termination clauses in the Acme Corp agreement?
Within seconds, your AI assistant searches through your personal document library and responds with the exact information, complete with a link to view the full document. No VPN, no laptop, no special apps - just Discord on your phone and the power of Cloudflare's edge network.
This isn't just another chatbot. It's your team's shared AI knowledge base that travels with you everywhere, with natural role-based access through Discord's channel permissions.
- User sends message in Discord → Bot receives message with channel context
- Bot processes commands → Determines AI model and features to use
- Bot forwards to Cloudflare Worker → Worker handles AI processing
- Worker searches documents (if requested) → AutoRAG searches channel's indexed files
- Worker calls AI model → Gets response from selected AI
- Worker stores conversation history → Saves to D1 database by channel
- Bot sends response → User receives AI-generated answer in Discord
- Runs in Docker container
- Monitors Discord channels for messages
- Handles file uploads to R2 storage
- Routes requests to Cloudflare Worker
- Manages user permissions and quotas
- Processes AI requests at the edge
- Manages conversation history in D1 database
- Integrates with AI models:
- External models (Anthropic, OpenAI) via AI Gateway
- Native Meta Llama via Workers AI
- Provides web-based file browser interface
- Handles document search via AutoRAG
- R2: Object storage for files organized by channel (
channels/{channelId}/
) - D1: SQL database for conversation history
- KV: Key-value store for user settings and preferences
- Feature flags (can_use_claude, can_use_openai, can_upload_files, can_use_autorag)
- Channel preferences (default AI model per channel)
- User quotas and limits
- OAuth sessions and authentication
When a user sends a message in Discord:
- Bot automatically knows user's channel access through Discord permissions
- Bot verifies user hasn't exceeded daily message quota
- Bot identifies any command prefixes (
!
,#
) or file attachments - No hardcoded channel lists - truly role-based access control
The bot supports several command types:
!claude
- Set Claude as default AI for the channel!chatgpt
- Set ChatGPT as default AI for the channel!llama
- Set Llama as default AI for the channel!docs
- Enable document search for the channel#claude
- Use Claude for just this message#docs
- Search documents for just this message!sync
- Manually sync documents with AutoRAG indexing
The Discord bot sends a request to the Cloudflare Worker with:
- User ID and username
- Message content
- Channel ID for conversation context
- Selected AI model preference
- Document search flag (if applicable)
- User settings and permissions
If document search is enabled:
- Worker queries AutoRAG with the user's message
- AutoRAG searches through indexed documents in the user's namespace
- Relevant document excerpts are included as context for the AI
- File references are converted to clickable links to the file browser
The worker routes to the appropriate AI based on user preference:
- Claude (Anthropic): Advanced reasoning and analysis - accessed via Cloudflare AI Gateway
- ChatGPT (OpenAI): General purpose conversations - accessed via Cloudflare AI Gateway
- Llama (Meta): Default free-tier model - runs natively on Cloudflare Workers AI
- Claude Code (Opus-4): Specialized coding model - accessed via Cloudflare AI Gateway (restricted to specific channel)
The worker manages conversation context:
- Stores unlimited conversation history in D1 database
- Intelligently retrieves the most recent messages (up to 150) for AI context
- Maintains separate history per channel - conversations never mix
- Full history always available, with smart windowing for optimal AI performance
- Preserves complete context for follow-up questions
The AI model generates a response considering:
- Current message
- Conversation history
- Document context (if applicable)
- System prompts for helpful behavior
The worker sends the response back to Discord:
- Long responses are automatically split into multiple messages
- File references include clickable links to the file browser
- Rate limiting prevents message flooding
- User attaches files to a Discord message in any channel
- Bot downloads files from Discord
- Bot uploads to R2 at path:
channels/{channelId}/{filename}
- Files are automatically indexed by AutoRAG for searching
- Files are associated with the channel - accessible to all channel members
- Web interface at
https://aibot.schenanigans.com/
- OAuth authentication via Discord (requests
identify
andguilds
scopes) - Browse all channels you have access to in the Discord server
- Channel-based file organization - see files from any channel you can access
- Vintage Mac OS-inspired interface with traffic light buttons
- Direct links to specific folders from document search results
File Management
- Drag-and-drop file upload
- Folder creation and organization
- Multi-part upload for large files
- Right-click context menu for advanced options
- HTTP/Custom metadata editing
File Handling
- In-browser file preview for:
- PDF documents
- Images (PNG, JPG, GIF)
- Text files
- Markdown files
- CSV files
- Logpush files
- In-browser file editing
- Folder upload support
Login screen with Discord OAuth
Native file browser interface for managing uploaded documents
- Dynamic Channel Access: OAuth flow fetches channels from Discord API
- No Hardcoded Lists: If you're in a channel, you have access - simple as that
- Bot Token Integration: Uses Discord bot to fetch all server channels
- Graceful Fallbacks: User OAuth token as backup if bot token fails
- Per-user permissions for AI models and features
- Daily message quotas to prevent abuse
- File size limits for uploads
- Channel-based storage paths (
channels/{channelId}/
) - Dynamic permission checks - if you can see the Discord channel, you can access its files
- No hardcoded permissions - purely role-based through Discord
- Shared AutoRAG namespace for all users (documents tagged by channel)
- Channel-based conversation history
- OAuth flow dynamically fetches user's accessible channels
- Discord Bot: Node.js with Discord.js
- Runtime: Docker container with health monitoring
- Edge Computing: Cloudflare Workers
- AI Models:
- Cloudflare AI Gateway (Anthropic Claude, OpenAI GPT)
- Cloudflare Workers AI (Meta Llama)
- Object Storage: Cloudflare R2
- Database: Cloudflare D1 (SQLite)
- Search: Cloudflare AutoRAG (Vectorize)
- Configuration: KV namespaces
- Multi-Model Support: Switch between different AI models on demand
- Channel-Based Documents: Upload and search documents organized by Discord channel
- True Role-Based Access: If you're in the channel, you have access - no configuration needed
- Unlimited Conversation Memory: Never lose context - all conversations stored permanently by channel
- Native File Browser: Vintage Mac OS-inspired web interface for managing files
- OAuth Integration: Seamless Discord authentication with dynamic channel discovery
- Flexible Commands: Channel defaults or per-message overrides
- High Performance: Edge-based processing for low latency
One of the most powerful features is complete mobile accessibility. Since everything runs through Discord:
- Search channel documents from iPhone, Android, or any device with Discord
- No app installation required - works through native Discord apps
- Full AI capabilities on the go - ask questions about your team's documents from anywhere
- Upload files directly from mobile - take a photo, save a PDF, instantly searchable by your team
- Your team's AI knowledge base travels with you - plane, train, or coffee shop
- Natural permissions - see a Discord channel? You can access its documents and AI
Example mobile workflow:
[On iPhone at a meeting]
User: #docs What were the payment terms in the Johnson contract?
Bot: Based on documents in this channel, the Johnson contract specifies NET 30 payment terms...
[Contract.pdf](https://aibot.schenanigans.com/?path=channels%2F1392959736600592534%2Fcontracts)
User: What's quantum computing?
Bot: Quantum computing is a type of computation that uses quantum bits...
User: #docs What were the terms in my lease agreement?
Bot: Based on documents in this channel, the key terms from your lease are...
[lease_agreement.pdf](https://aibot.schenanigans.com/?path=channels%2F1392959736600592534%2Fdocuments)
Real example showing AutoRAG sync and document search with German tax documents
User: !claude
Bot: Claude set as default for this channel
User: Explain the theory of relativity
Bot: [Claude responds with detailed explanation]
User: [Attaches contract.pdf]
Bot: Uploading 1 file to this channel's storage...
contract.pdf: File uploaded successfully
Your files are being indexed for search
The system uses Discord OAuth to dynamically determine user access:
- User visits
https://aibot.schenanigans.com/
- Redirected to Discord OAuth with scopes:
identify guilds
- Discord returns user info and guild memberships
- Worker fetches channels using Discord Bot token
- Filters to text channels user can access
- Creates session with allowed channels
- File browser shows only accessible channels
This means:
- Zero configuration - No hardcoded channel lists
- Instant updates - New channel? Instant access
- Role changes reflected immediately - Lost access? Can't see files
- True RBAC - Discord permissions are the single source of truth
Discord User
↓ (message/file)
Discord Bot (Node.js)
↓ (API request with channelId)
Cloudflare Worker
↓ ↙ ↘
AutoRAG D1 AI Gateway
↓ ↓ ↓
↓ ↓ AI Models
↓ ↓ (Claude/GPT/Llama)
← ← ← ← ← ←
↓ (response)
Discord User