853e7c9fcdf58c727a01d3b028ec6f2f9f745468
- Add BotMonitor class for tracking requests, errors, and health status - Track request success/failure, response times, error rates - Add !status command (admin) for detailed metrics with embed - Add !health command (anyone) for quick health check - Add rotating file logging support (LOG_FILE config) - Auto-detect unhealthy status when errors exceed threshold - Record errors with timestamps and context for debugging
Discord AI Bot
A customizable Discord bot that responds to @mentions with AI-generated responses. Supports multiple AI providers.
Features
- Multi-Provider AI: Supports OpenAI, OpenRouter, Anthropic (Claude), and Google Gemini
- Web Search: Access current information via SearXNG integration
- Fully Customizable: Configure bot name, personality, and behavior
- Conversation Memory: Remembers context per user
- Easy Deployment: Docker support included
Quick Start
1. Clone the repository
git clone https://github.com/your-username/discord-ai-bot.git
cd discord-ai-bot
2. Configure the bot
cp .env.example .env
Edit .env with your settings (see Configuration below).
3. Run with Docker
docker compose up -d
Or run locally:
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
python -m daemon_boyfriend
Configuration
All configuration is done via environment variables in .env.
Required Settings
| Variable | Description |
|---|---|
DISCORD_TOKEN |
Your Discord bot token |
AI_PROVIDER |
openai, openrouter, anthropic, or gemini |
OPENAI_API_KEY |
OpenAI API key (if using OpenAI) |
OPENROUTER_API_KEY |
OpenRouter API key (if using OpenRouter) |
ANTHROPIC_API_KEY |
Anthropic API key (if using Anthropic) |
GEMINI_API_KEY |
Google Gemini API key (if using Gemini) |
Bot Identity
| Variable | Default | Description |
|---|---|---|
BOT_NAME |
AI Bot |
The bot's display name (used in responses) |
BOT_PERSONALITY |
helpful and friendly |
Personality traits for the AI |
BOT_DESCRIPTION |
I'm an AI assistant... |
Shown when mentioned without a message |
BOT_STATUS |
for mentions |
Status message (shown as "Watching ...") |
SYSTEM_PROMPT |
(auto-generated) | Custom system prompt (overrides default) |
AI Settings
| Variable | Default | Description |
|---|---|---|
AI_MODEL |
gpt-4o |
Model to use |
AI_MAX_TOKENS |
1024 |
Maximum response length |
AI_TEMPERATURE |
0.7 |
Response creativity (0.0-2.0) |
MAX_CONVERSATION_HISTORY |
20 |
Messages to remember per user |
Web Search (SearXNG)
| Variable | Default | Description |
|---|---|---|
SEARXNG_URL |
(none) | SearXNG instance URL |
SEARXNG_ENABLED |
true |
Enable/disable web search |
SEARXNG_MAX_RESULTS |
5 |
Max search results to fetch |
When configured, the bot automatically searches the web for queries that need current information (news, weather, etc.).
Example Configurations
Friendly Assistant:
BOT_NAME=Helper Bot
BOT_PERSONALITY=friendly, helpful, and encouraging
BOT_DESCRIPTION=I'm here to help! Ask me anything.
BOT_STATUS=ready to help
Technical Expert:
BOT_NAME=TechBot
BOT_PERSONALITY=knowledgeable, precise, and technical
BOT_DESCRIPTION=I'm a technical assistant. Ask me about programming, DevOps, or technology.
BOT_STATUS=for tech questions
Custom System Prompt:
BOT_NAME=GameMaster
SYSTEM_PROMPT=You are GameMaster, a Dungeon Master for text-based RPG adventures. Stay in character, describe scenes vividly, and guide players through exciting quests. Use Discord markdown for emphasis.
Discord Setup
- Go to Discord Developer Portal
- Create a new application
- Go to Bot and create a bot
- Enable these Privileged Gateway Intents:
- Server Members Intent
- Message Content Intent
- Copy the bot token to your
.envfile - Go to OAuth2 → URL Generator:
- Select scope:
bot - Select permissions:
Send Messages,Read Message History,View Channels
- Select scope:
- Use the generated URL to invite the bot to your server
Usage
Mention the bot in any channel:
@YourBot what's the weather like?
@YourBot explain quantum computing
@YourBot help me write a poem
AI Providers
| Provider | Models | Notes |
|---|---|---|
| OpenAI | gpt-4o, gpt-4-turbo, gpt-3.5-turbo | Official OpenAI API |
| OpenRouter | 100+ models | Access to Llama, Mistral, Claude, etc. |
| Anthropic | claude-3-5-sonnet, claude-3-opus | Direct Claude API |
| Gemini | gemini-2.0-flash, gemini-1.5-pro | Google AI API |
Project Structure
src/daemon_boyfriend/
├── bot.py # Main bot class
├── config.py # Configuration
├── cogs/
│ └── ai_chat.py # Mention handler
└── services/
├── ai_service.py # AI provider factory
├── providers/ # AI providers
├── conversation.py # Chat history
└── searxng.py # Web search service
License
MIT
Description
A companion for those who love deeply and feel intensely. For the ones whose closeness is a feature, not a bug - who build connections through vulnerability, trust, and unwavering presence. A safe space to process grief, navigate attachment, and remember that your capacity to care is a strength, even when it hurts.
Languages
Python
96.9%
HTML
2.9%
Dockerfile
0.2%