Overview
Bot Planning can be deployed using Docker, which provides an isolated environment with all required dependencies. This method ensures consistency across different environments and simplifies deployment.Prerequisites
- Docker installed on your system
- A Discord bot token from Discord Developer Portal
- Google Sheets URL for your planning/schedule (exported as CSV)
Dockerfile Explanation
The project uses the following Dockerfile:- Base Image: Uses
python:3.11-slimfor a lightweight Python environment - Working Directory: Sets
/appas the working directory inside the container - Copy Files: Copies
requirements.txtfirst (for layer caching), then all project files - Install Dependencies: Installs Python packages:
discord.py- Discord bot frameworkpandas- Data manipulation for CSV processingmatplotlib- Image generation for schedulespython-dotenv- Environment variable management
- Start Command: Launches the bot with
python bot.py
Environment Configuration
Create a.env file in your project directory with the following variables:
Important: The
EDT_PATH must end with /export?format=csv to properly export the Google Sheets data.Deployment Steps
Create Discord Bot
Navigate to the Discord Developer Portal and create a new bot application. Copy your bot token.
Prepare Environment File
Create a
.env file in your project directory with your DISCORD_TOKEN and EDT_PATH variables.Build Docker Image
Build the Docker image from the Dockerfile:This creates an image tagged as
bot-planning with all dependencies installed.Run the Container
Start the bot container with your environment configuration:Command options explained:
-d- Run container in detached mode (background)--name bot-planning- Assign a friendly name to the container--env-file .env- Load environment variables from.envfile--restart always- Automatically restart container if it stopsbot-planning:latest- Use the image we just built
Restart Policy: The
--restart always flag ensures your bot automatically restarts after system reboots or if the container crashes. This is crucial for maintaining uptime in production.Managing the Container
Stop the Bot
Start the Bot
Restart the Bot
Remove the Container
View Resource Usage
Updating the Bot
When you need to update the bot code:Troubleshooting
Container Exits Immediately
Check the logs for errors:- Invalid Discord token
- Incorrect Google Sheets URL format
- Missing environment variables
Environment Variables Not Loading
Verify your.env file path is correct and the file exists: