-
Notifications
You must be signed in to change notification settings - Fork 0
Configuration
This guide covers all configuration options for the Discord bot, including environment variables, settings files, and runtime configuration.
- Environment Variables
- Configuration Files
- Bot Settings
- Feature Configuration
- Security Settings
- Logging Configuration
- Advanced Configuration
These variables must be set for the bot to function:
# Discord Bot Token (Required)
DISCORD_TOKEN=your_discord_bot_token_hereHow to get Discord Token:
- Go to Discord Developer Portal
- Select your application
- Go to "Bot" tab
- Copy the token under "TOKEN"
# Bot prefix for commands (default: !)
COMMAND_PREFIX=!
# Bot status message (default: "Watching Discord!")
STATUS_MESSAGE=Online and ready!
# Activity type (default: watching)
# Options: playing, listening, watching, competing
ACTIVITY_TYPE=watching# Database file path (default: data/bot.db)
DATABASE_PATH=data/bot.db
# Database backup interval in hours (default: 24)
BACKUP_INTERVAL=24# Log level (default: INFO)
# Options: DEBUG, INFO, WARNING, ERROR, CRITICAL
LOG_LEVEL=INFO
# Log file path (default: data/logs/bot.log)
LOG_FILE=data/logs/bot.log
# Enable console logging (default: true)
CONSOLE_LOGGING=true# GitHub Integration
GITHUB_TOKEN=your_github_personal_access_token
GITHUB_USERNAME=your_github_username
# osu! Integration
OSU_API_KEY=your_osu_api_key
OSU_DEFAULT_MODE=standard # standard, taiko, catch, mania, fruits
# Webhook Configuration
WEBHOOK_URL=your_discord_webhook_url
WEBHOOK_USERNAME=Bot WebhookLocation: data/config/bot.json
{
"bot": {
"name": "Discord Bot",
"version": "1.0.0",
"description": "Feature-rich Discord bot",
"prefix": "!",
"status": {
"message": "Online and ready!",
"activity": "watching",
"type": "competing"
}
},
"features": {
"admin": {
"enabled": true,
"clear_limit": 100,
"timeout_duration": 300
},
"achievements": {
"enabled": true,
"auto_save": true,
"notification_channel": null
},
"anti_spam": {
"enabled": true,
"max_messages": 5,
"time_window": 10,
"punishment": "mute"
},
"message_logging": {
"enabled": true,
"log_edits": true,
"log_deletes": true,
"exclude_channels": []
}
},
"guilds": {
"guild_id": {
"prefix": "!",
"admin_role": "Admin",
"mod_role": "Moderator",
"welcome_channel": "welcome",
"log_channel": "logs"
}
}
}Each guild can have individual settings:
{
"guilds": {
"123456789012345678": {
"prefix": "!",
"admin_role": "Server Admin",
"mod_role": "Moderator",
"welcome_channel": "welcome",
"log_channel": "moderation-logs",
"features": {
"anti_spam": {
"enabled": true,
"max_messages": 3,
"time_window": 5
},
"message_logging": {
"enabled": true,
"exclude_channels": ["admin-only", "bot-commands"]
}
}
}
}
}The bot supports multiple command prefixes:
# Single prefix
COMMAND_PREFIX=!
# Multiple prefixes (comma-separated)
COMMAND_PREFIX=!,?,-
# Mention-based prefix (always enabled)
# Users can mention the bot instead of using prefixConfigure bot's Discord status:
# Playing status
ACTIVITY_TYPE=playing
STATUS_MESSAGE=with commands
# Watching status
ACTIVITY_TYPE=watching
STATUS_MESSAGE=for new messages
# Listening status
ACTIVITY_TYPE=listening
STATUS_MESSAGE=to user commands
# Competing status
ACTIVITY_TYPE=competing
STATUS_MESSAGE=in a coding challengeDiscord requires explicit intent configuration:
# Enable privileged intents (requires verification in Discord Developer Portal)
ENABLE_MESSAGE_CONTENT=true
ENABLE_MEMBERS=true
ENABLE_PRESENCES=true{
"admin": {
"enabled": true,
"commands": {
"clear": {
"enabled": true,
"default_amount": 10,
"max_amount": 100,
"required_permission": "manage_messages"
},
"kick": {
"enabled": true,
"required_permission": "kick_members",
"log_action": true
},
"ban": {
"enabled": true,
"required_permission": "ban_members",
"log_action": true,
"default_reason": "Violation of server rules"
},
"mute": {
"enabled": true,
"required_permission": "moderate_members",
"default_duration": 300,
"max_duration": 604800
}
}
}
}{
"achievements": {
"enabled": true,
"auto_save": true,
"save_interval": 300,
"notification_channel": null,
"achievements": {
"first_message": {
"name": "First Steps",
"description": "Send your first message",
"rarity": "common",
"points": 10
},
"message_master": {
"name": "Message Master",
"description": "Send 1000 messages",
"rarity": "legendary",
"points": 1000
}
}
}
}{
"anti_spam": {
"enabled": true,
"detection": {
"max_messages": 5,
"time_window": 10,
"similar_content_threshold": 0.8
},
"punishment": {
"type": "mute",
"duration": 300,
"warn_before_punishment": true
},
"exemptions": {
"roles": ["Admin", "Moderator"],
"channels": ["spam-allowed"]
}
}
}{
"message_logging": {
"enabled": true,
"log_edits": true,
"log_deletes": true,
"log_reactions": true,
"storage": {
"type": "json",
"file_path": "data/logs/messages.json",
"rotation": {
"enabled": true,
"max_file_size": "100MB",
"max_files": 10
}
},
"filters": {
"exclude_channels": ["admin-only", "bot-commands"],
"exclude_users": ["bot_id"],
"exclude_content": ["secret", "password"]
}
}
}# Enable token encryption (experimental)
TOKEN_ENCRYPTION=false
# Token encryption key (if encryption enabled)
TOKEN_ENCRYPTION_KEY=your_32_character_encryption_key{
"rate_limiting": {
"enabled": true,
"global_limit": {
"requests": 100,
"period": 60
},
"user_limit": {
"requests": 10,
"period": 60
},
"exemptions": {
"roles": ["Admin", "Premium"],
"users": ["bot_owner_id"]
}
}
}{
"blacklist": {
"users": [
{
"user_id": "123456789",
"reason": "Spamming",
"banned_by": "Admin",
"timestamp": "2024-01-01T00:00:00Z"
}
],
"guilds": [],
"auto_save": true
}
}# Log level configuration
LOG_LEVEL=INFO
LOG_FORMAT=%(asctime)s - %(name)s - %(levelname)s - %(message)s
LOG_DATE_FORMAT=%Y-%m-%d %H:%M:%S{
"logging": {
"rotation": {
"enabled": true,
"max_size": "50MB",
"backup_count": 5,
"compression": "gzip"
},
"handlers": {
"file": {
"enabled": true,
"level": "INFO"
},
"console": {
"enabled": true,
"level": "DEBUG"
},
"discord": {
"enabled": false,
"channel_id": "log_channel_id",
"level": "WARNING"
}
}
}
}{
"structured_logging": {
"enabled": false,
"format": "json",
"fields": {
"timestamp": true,
"level": true,
"logger": true,
"message": true,
"guild_id": true,
"user_id": true,
"command": true
}
}
}# Discord gateway settings
GATEWAY_COMPRESSION=true
MAX_MESSAGE_SIZE=2000
HEARTBEAT_TIMEOUT=60
# Async settings
MAX_CONCURRENT_TASKS=100
TASK_TIMEOUT=300{
"cache": {
"enabled": true,
"type": "memory",
"ttl": 3600,
"max_size": 1000,
"strategies": {
"user_data": true,
"guild_data": true,
"command_cooldowns": true
}
}
}# SQLite configuration
DATABASE_PATH=data/bot.db
DATABASE_TIMEOUT=30
DATABASE_CHECK_SAME_THREAD=false
# Connection pooling
DATABASE_POOL_SIZE=5
DATABASE_MAX_OVERFLOW=10# Enable web server for webhooks
WEB_SERVER_ENABLED=false
WEB_SERVER_HOST=127.0.0.1
WEB_SERVER_PORT=8080
WEB_SERVER_SSL=falseRun the configuration validator to check your setup:
python scripts/validate_config.pyMissing Required Variables:
Error: DISCORD_TOKEN is required but not set
Solution: Add the missing variable to your .env file
Invalid JSON:
Error: Invalid JSON in data/config/bot.json
Solution: Use a JSON validator to fix syntax errors
Permission Issues:
Error: Cannot write to data directory
Solution: Check directory permissions and ownership
# Development settings
DEBUG=true
LOG_LEVEL=DEBUG
RELOAD_ON_CHANGE=true# Production settings
DEBUG=false
LOG_LEVEL=INFO
RELOAD_ON_CHANGE=false
TOKEN_ENCRYPTION=true# Testing settings
TEST_MODE=true
MOCK_DISCORD_API=true
LOG_LEVEL=DEBUGWhen upgrading bot versions:
- Backup current configuration
cp data/config/bot.json data/config/bot.json.backup- Check for new configuration options
python scripts/check_config_migration.py-
Update configuration file
- Add new required fields
- Remove deprecated options
- Update existing values
-
Validate new configuration
python scripts/validate_config.py-
Never commit
.envfiles to version control - Use strong, unique tokens for each deployment
- Rotate tokens regularly (every 90 days)
- Limit bot permissions to only what's necessary
- Monitor audit logs for suspicious activity
- Use appropriate log levels for production
- Enable log rotation to prevent disk space issues
- Configure caching for frequently accessed data
- Monitor resource usage and adjust limits
- Use structured logging for better analysis
- Regular backups of configuration and data
- Document custom configurations for team reference
- Test configuration changes in development first
- Monitor configuration validation results
- Keep configuration files in version control (except secrets)
Configuration complete! Your bot should now be properly configured for your specific needs.