mjpin Discord Bot Documentation
Comprehensive user documentation for the mjpin Discord bot – automated Pinterest pinning and Midjourney prompt generation.
What mjpin Does
mjpin automates three core workflows:
- Pinterest Integration: Pin Discord images to Pinterest boards with multi-account support and rate limiting
- Automated Image Search: Search channel history for keyword-matching images and automatically pin them
- Prompt Generation: Generate Midjourney prompts using OpenAI with customizable system prompts
Documentation Structure
Commands
/pin– Search channel history for keyword-matching images and pin to Pinterest boards/prompt– Generate Midjourney prompts with OpenAI
/auth– Link Pinterest accounts via OAuth2/sync– Synchronize Pinterest boards/settings– View and switch between Pinterest accounts
/model– Configure OpenAI model per server/editprompt– Edit system prompt sections/restart– Restart bot with confirmation
Integrations
- OAuth2 authentication flow
- Multi-account architecture
- Board synchronization
- Pin creation
- Rate limiting (100 pins per 12 hours per account)
- Model selection and filtering
- Modular system prompt assembly
- Chat completions API
- Per-guild configuration
- Command registration
- Interaction handling
- Message fetching and pagination
- Permission checks
- Error handling
Data Management
- File-based JSON storage
- Pinterest token management
- Board caching
- Rate limit tracking
- Model settings
- Sliding window algorithm
- Per-account tracking
- Multi-account support
- Enforcement points
- Channel history search
- Keyword variant generation
- Image detection
- Message ID extraction
Configuration
- Discord configuration
- Pinterest OAuth credentials
- OpenAI API key
- Optional fallback settings
- PM2 process management
- Restart behavior
- Data persistence
- Monitoring and logging
Quick Start
For Users:
- Run
/authto link Pinterest account - Run
/syncto cache Pinterest boards - Run
/pinwith keyword and url parameters to automatically find and pin matching images
For Server Admins:
- Configure OpenAI model:
/model - Edit system prompts:
/editprompt - Monitor via
/settings
For Bot Operators:
- Configure environment variables
- Deploy with PM2
- Preserve data/ directory across updates
Key Features
Multi-Account Pinterest Support:
- Link multiple Pinterest accounts per Discord user
- Switch between accounts via
/settings - Separate rate limits per account
- 100 pins per 12 hours per account
Intelligent Image Search:
- Automatic keyword variant generation (singular/plural)
- Searches after last
/pincommand - Detects Midjourney upscaled images only
- Pins up to 10 matching images per command
Customizable Prompt Generation:
- Per-guild OpenAI model selection
- Modular system prompt from .txt files
- Live editing via Discord modals
- Automatic prompt reloading
Comprehensive Error Handling:
- Graceful degradation on failures
- User-friendly error messages
- Automatic retry logic
- Process-level error handlers
Architecture
Modular Command Structure:
- Commands in
src/commands/ - Services in
src/services/ - Utilities in
src/utils/ - Data in
data/directory
Service Layer:
- Pinterest API integration
- OpenAI API integration
- Model settings management
Utility Layer:
- JSON file management
- Rate limit tracking
- Message search operations
Data Storage:
- File-based JSON storage
- No database required
- Single data/ directory
Component Coverage
Commands (8):
- pin, prompt, auth, sync, settings, model, editprompt, restart
Services (3):
- pinterest.js, openai.js, modelSettings.js
Utilities (3):
- jsonFileManager.js, pinRateLimit.js, messageSearch.js
Data Files (5 + user .txt files):
- pinterest_tokens.json, boards.json, pin_counts.json, model_settings.json, restart_info.json
API Integrations (3):
- Pinterest API v5
- OpenAI API v1
- Discord API v10
User Workflows
Pinning Workflow:
- Authenticate with Pinterest via
/auth - Sync boards via
/sync - Select active account via
/settings(if multiple accounts) - Use
/pinwith keyword (used as board name) and URL - Bot searches channel history for keyword-matching images
- Bot pins found images and tracks rate limit
Prompt Generation Workflow:
- Admin configures model via
/model - Admin customizes system prompt via
/editprompt - Users run
/promptwith input description - Bot returns generated Midjourney prompt
Technical Requirements
Runtime:
- Node.js
- npm packages (see package.json)
External Services:
- Discord Bot (requires bot token and guild ID)
- Pinterest App (requires OAuth credentials)
- OpenAI API (requires API key)
Deployment:
- PM2 process manager recommended
- Publicly accessible callback URL for Pinterest OAuth
- Persistent data/ directory
Security Considerations
Token Storage:
- OAuth tokens stored in data/pinterest_tokens.json
- Access tokens never logged
- File permissions should restrict access
Environment Variables:
- All secrets in environment variables
- Never commit .env file
- Use PM2 ecosystem config for production
Permission Checks:
- Admin commands require Administrator or Manage Server permissions
- Ephemeral messages for sensitive information
- OAuth state parameter validates Discord user ID