AI-powered Discord bot for DCS Squadron Standard Operating Procedures (SOPs). Built with OpenAI Assistants API, OPSObot is a hosted service that helps squadrons upload their SOP documents and provides interactive Q&A and quiz functionality to keep members sharp on procedures.
- Hosted Service: Centralized API key management - no need for users to provide their own OpenAI keys
- Per-Server Isolation: Each Discord server gets its own dedicated vector store for complete document isolation
- Document Upload: Admins can upload various document types (PDF, Word, PowerPoint, text, images) that the bot uses to answer questions
- Q&A System: Ask questions about your SOPs and get answers grounded in your uploaded documents
- Quiz System: Generate timed quizzes from your SOP documents to test squadron knowledge
- Intelligent Responses: Powered by GPT-4 with vector search for accurate, citation-backed answers
- Monetization Ready: Architecture supports subscription tiers and premium features
- Single OpenAI API key controlled by bot owner
- Reduces complexity for end users
- Enables hosted SaaS model with potential for premium tiers
- Each Discord server gets its own OpenAI Assistant
- Each server has a dedicated Vector Store for documents
- Zero cross-contamination: Server A's documents are never accessible to Server B
- Documents are tagged and isolated at the vector store level
- Discord bot token (Create a bot)
- OpenAI API key (bot owner provides this - users don't need their own)
- Python 3.11+
- Clone the repository:
git clone https://github.com/joemurrell/OPSObot.git
cd OPSObot- Install dependencies:
pip install -r requirements.txt- Set environment variables:
export DISCORD_TOKEN="your-discord-bot-token"
export OPENAI_API_KEY="your-openai-api-key" # Bot owner's key- Run the bot:
python app.py- Go to Discord Developer Portal
- Create a new application
- Go to "Bot" section and create a bot
- Enable these Privileged Gateway Intents:
- Message Content Intent
- Go to "OAuth2" > "URL Generator"
- Select scopes:
bot,applications.commands - Select bot permissions:
- Send Messages
- Embed Links
- Read Message History
- Use Slash Commands
- Use the generated URL to invite the bot to your server
- Initialize the bot for your server:
/setup
This creates a dedicated OpenAI Assistant and isolated vector store for your server. No API key needed from you!
- Upload SOP documents:
/upload document:<attach-file>
Upload your squadron's SOP documents. The bot will process and index them in your server's private vector store.
Supported file types:
- Documents: PDF, Word (.doc, .docx)
- Presentations: PowerPoint (.ppt, .pptx)
- Text: TXT, Markdown (.md)
- Images: JPG, PNG, GIF, BMP, WebP
- View uploaded documents:
/list_documents
- Remove a document (if needed):
/remove_document file_id:<file-id-from-list>
Ask questions about your SOPs:
/ask question:What is the standard radio frequency for tower?
Start a quiz:
/quiz_start questions:6 duration:5 topic:radio procedures
questions: Number of questions (1-10)duration: Quiz duration in minutes (1-60)topic: Optional topic focus
Check your quiz progress:
/quiz_score
End a quiz early:
/quiz_end
View bot information:
/info
- Centralized API: Bot owner provides a single OpenAI API key
- Per-Guild Setup: Each Discord server runs
/setupto create their own Assistant and Vector Store - Document Isolation: Uploaded documents go into the server's dedicated vector store
- Grounded Responses: All answers use only documents from that server's vector store
- Quiz Generation: AI generates diverse multiple-choice questions from server-specific documents
- API Key: Centrally managed by bot owner - users never handle OpenAI credentials
- Document Isolation: Each server's documents are stored in a separate vector store
- No Cross-Contamination: Vector store IDs ensure complete data separation between servers
- Admin Controls: Only server administrators can configure and upload documents
- File Type Security: Only safe document types allowed (no executable code or scripts)
- Local Config: Server configurations stored in
guild_configs.json(persisted in Railway volume or local directory)
The bot now includes built-in monetization features using Discord's native monetization system:
- File uploads: Up to 5 MB per document
/askcommand: 3 queries per day/quiz_startcommand: 1 quiz per day
- File uploads: Up to 50 MB per document
/askcommand: Unlimited/quiz_startcommand: Unlimited
For detailed information about limits and implementation, see MONETIZATION_FEATURES.md.
The centralized API key model allows the bot owner to:
- Track usage per guild
- Implement rate limiting
- Enforce tier limits
- Bill based on actual usage
The bot includes a railway.json and Dockerfile for easy deployment:
- Connect your GitHub repo to Railway
- Set the required environment variables:
DISCORD_TOKEN- Your Discord bot tokenOPENAI_API_KEY- Your OpenAI API keyPREMIUM_SKU_ID(optional) - Your Discord premium tier SKU ID for monetization
- Add a persistent volume to ensure guild configurations survive deployments:
- In Railway dashboard, go to your service
- Click "Variables" tab, then "Volume" section
- Click "Add Volume"
- Set mount path:
/data - Set volume size: 1GB (or more if needed)
- Deploy!
Each guild will still need to run /setup to initialize their assistant and vector store.
Configuration Persistence: Guild configurations are stored in guild_configs.json within the /data volume (or local directory for development). This ensures that server setups persist across deployments and restarts. The bot will automatically load existing configurations on startup.
Note: Without a persistent volume, guild configurations will be lost on each new deployment. The volume ensures your data persists even when the container is rebuilt.
- Discord.py: Discord bot framework with slash commands
- OpenAI Assistants API v2: AI-powered Q&A with file search capability
- Vector Stores: Document embeddings for semantic search (see
guild_configs.example.jsonfor structure) - JSON Storage: Simple file-based storage for guild configurations
MIT License - see LICENSE file
Contributions welcome! Please open an issue or PR.
For issues or questions, please open a GitHub issue.
- Ensure the bot has been added to your server with the correct permissions
- Run
/infoto check if the server is configured - Check that the bot has permissions in the channel (Send Messages, Embed Links, etc.)
- Verify the
OPENAI_API_KEYenvironment variable is set correctly (bot owner) - Check that you have access to the Assistants API (may require a paid OpenAI account)
- Ensure you're running the command in a server (not DMs) and have Administrator permissions
- Check that your file type is supported (PDF, Word, PowerPoint, text, or image files)
- Verify your OpenAI account has sufficient storage quota
- Ensure the file isn't too large (OpenAI has file size limits)
- For security, only common document types are allowed (no .py, .exe, .sh, etc.)
- An admin needs to run
/setupfirst to initialize the server - Check that documents have been uploaded with
/upload - Try
/infoto see the server's configuration status
- Upload more diverse SOP documents
- Try specifying a
topicparameter in/quiz_startto focus on specific areas - The bot attempts to generate diverse questions, but limited source material may result in similar questions
- This should never happen! Each server has its own isolated vector store
- If you experience this, please report it immediately as it's a critical bug