-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
Reference for all configuration options in the Wisp Framework.
See also: Deployment-Guide | Troubleshooting | Architecture-Overview
- Environment Variables
- Configuration Loading
- Discord Intents
- Database Configuration
- Redis Configuration
- Logging Configuration
- Service Configuration
Configuration is loaded from environment variables and optional .env files.
Discord bot token. Required.
DISCORD_TOKEN=your_bot_token_hereEnvironment name. Determines which .env.{ENV} file to load. Default: local
ENV=productionPostgreSQL database connection URL. Optional (requires [db] extra).
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/discord_bot
⚠️ SECURITY WARNING: Change default passwords fromdocker-compose.ymlbefore production!
Redis connection URL. Optional (requires [redis] extra).
REDIS_URL=redis://localhost:6379/0Logging level. Default: INFO
Valid values: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=DEBUGWhether to sync slash commands on startup. Default: true
SYNC_ON_STARTUP=falseDiscord user ID of the bot owner. Used for owner-only commands.
OWNER_ID=123456789012345678Default welcome channel ID for guilds.
WELCOME_CHANNEL_ID=987654321098765432Configure Discord gateway intents via environment variables. All default to true if not specified.
Guilds intent. Default: true
INTENTS_GUILDS=trueMembers intent. Default: true
INTENTS_MEMBERS=trueMessages intent. Default: true
INTENTS_MESSAGES=trueMessage content intent. Default: true
INTENTS_MESSAGE_CONTENT=trueReactions intent. Default: true
INTENTS_REACTIONS=trueVoice states intent. Default: true
INTENTS_VOICE_STATES=trueGuild messages intent. Default: true
INTENTS_GUILD_MESSAGES=trueDM messages intent. Default: true
INTENTS_DM_MESSAGES=trueDatabase connection pool size. Default: 10
DB_POOL_SIZE=20Maximum overflow connections. Default: 20
DB_MAX_OVERFLOW=30Connection pool timeout in seconds. Default: 30
DB_POOL_TIMEOUT=60When using Docker Compose, these variables configure the database:
PostgreSQL username. Default (dev): discord_bot
POSTGRES_USER=myuserPostgreSQL password. MUST be changed in production!
POSTGRES_PASSWORD=strong_password_herePostgreSQL database name. Default (dev): discord_bot
POSTGRES_DB=mydbThe framework loads environment variables from .env.{ENV} files:
- Check
ENVenvironment variable (default:local) - Load
.env.{ENV}file if it exists - Environment variables override file values
# Discord Configuration
DISCORD_TOKEN=your_token_here
OWNER_ID=123456789012345678
# Database Configuration
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/discord_bot
# Redis Configuration
REDIS_URL=redis://localhost:6379/0
# Logging
LOG_LEVEL=INFO
# Intents
INTENTS_GUILDS=true
INTENTS_MEMBERS=true
INTENTS_MESSAGES=true
INTENTS_MESSAGE_CONTENT=true# Discord Configuration
DISCORD_TOKEN=${DISCORD_TOKEN}
OWNER_ID=${OWNER_ID}
# Database Configuration (use environment variables, never defaults!)
DATABASE_URL=${DATABASE_URL}
POSTGRES_USER=${POSTGRES_USER}
POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
POSTGRES_DB=${POSTGRES_DB}
# Logging
LOG_LEVEL=WARNING
# Intents (only enable what you need)
INTENTS_GUILDS=true
INTENTS_MEMBERS=true
INTENTS_MESSAGES=false
INTENTS_MESSAGE_CONTENT=falseDepending on your bot's functionality, you may need specific intents:
- Guilds: Required for most bots
- Members: Required for member join/leave events
- Messages: Required for message events
- Message Content: Required to read message content
- Reactions: Required for reaction events
- Voice States: Required for voice channel events
- Go to Discord Developer Portal
- Select your application
- Go to "Bot" section
- Scroll to "Privileged Gateway Intents"
- Enable required intents
- Save changes
postgresql+asyncpg://[user[:password]@][host][:port][/database]
# Local database
DATABASE_URL=postgresql+asyncpg://user:password@localhost:5432/discord_bot
# Remote database
DATABASE_URL=postgresql+asyncpg://user:password@db.example.com:5432/discord_bot
# With SSL
DATABASE_URL=postgresql+asyncpg://user:password@db.example.com:5432/discord_bot?ssl=requireThe framework uses SQLAlchemy's connection pooling:
- Pool Size: Number of connections to maintain
- Max Overflow: Additional connections allowed beyond pool size
- Pool Timeout: Time to wait for a connection before timing out
redis://[password@]host[:port][/database]
# Local Redis
REDIS_URL=redis://localhost:6379/0
# Remote Redis with password
REDIS_URL=redis://password@redis.example.com:6379/0
# Redis Cluster
REDIS_URL=redis://node1:6379,node2:6379,node3:6379- DEBUG: Detailed information for debugging
- INFO: General informational messages
- WARNING: Warning messages
- ERROR: Error messages
- CRITICAL: Critical errors
The framework uses structured logging with correlation IDs:
import logging
logger = logging.getLogger(__name__)
logger.info("Message", extra={"key": "value"})No configuration required. Automatically checks all services.
Automatically uses Redis if REDIS_URL is set, otherwise uses in-memory cache.
No configuration required. Metrics are stored in memory.
No configuration required. Tasks are scheduled in memory.
Logs to Python's logging system. Configure via LOG_LEVEL.
Configure webhook URL via environment variable (if implemented).
Configured via DATABASE_URL and database-specific environment variables.
The framework validates configuration on startup:
-
Required Variables:
DISCORD_TOKENmust be present - Format Validation: URLs and IDs are validated
- Service Availability: Services check for required dependencies
If configuration is invalid:
from wisp_framework.config import ConfigError
try:
config = AppConfig()
except ConfigError as e:
print(f"Configuration error: {e}")- Use Environment Variables: Never hardcode sensitive values
-
Separate Environments: Use different
.envfiles for dev/prod - Change Defaults: Always change default passwords
- Minimal Intents: Only enable intents you need
- Secure Storage: Store production secrets securely
- Validate Early: Check configuration before deployment
- Document Custom Config: Document any custom configuration
- See Deployment-Guide for production configuration
- Check Troubleshooting for configuration issues
- Review Architecture-Overview for configuration context