Self‐Hosting a Discord Bot on a VPS
This guide provides a step-by-step process to self-host the CrossBan Discord bot on a Virtual Private Server (VPS). CrossBan is a bot for synchronizing bans across multiple Discord servers, built with TypeScript, Discord.js, and PostgreSQL. It's containerized with Docker for easy deployment.
Prerequisites
Minimum VPS Requirements
OS: Ubuntu 22.04 LTS or similar Linux distribution (recommended for Docker compatibility).
RAM: At least 2GB because Docker is known for eating RAM for breakfast.
Storage: 10GB+ free space (for Docker images, database, and logs). 20GB+ is better.
CPU: 2 cores (sufficient for moderate usage).
Software Requirements
Server Requirements
Docker: Version 27+ (use the newest version so you don't have to update it for a longer time)
Docker Compose: Version 2.39 (same thinking as above)
Git: For cloning the repository.
SSH Access: To your VPS for remote management.
Local Requirements
An SSH client like Termius to safely connect to your VPS and have an easy to use user interface.
Other Requirements
A Discord bot token (create one at the Discord Developer Portal). More to that later on.
Set up the Bot
Step 1: Prepare Your VPS
Connect to Your VPS with your SSH client.
Update the System:
Remember that you don't see the password you type in for safety reasons.
Install Docker and Docker Compose: Please refer to the offical Docker Docs for the correct installation method for your OS.
Install Git:
Verify Installations:
Step 2: Clone and Set Up the Repository
Clone the Repository:
Create Environment File:
Copy the example environment file:
Edit
.envwith your details:Fill in the placeholders.
Step 3: Invite the Bot to Your Servers
Go to the Discord Developer Portal.
Disable the General Install Link and only allow Guild Install.

Go to the Bot page and disable The Public bot and Regenerate your Bot's Token.

Disable Public bot because otherwise anyone will invite your bot - you don't want that. Under your bot application, go to OAuth2 > OAuth2 URL Generator.
Select scopes:
bot,applications.commands.Select permissions: Ban Members, View Audit Log, Send Messages, Use Slash Commands.
Use the generated URL to invite the bot to your servers.
Step 4: Configure and Run the Bot
Build and Start the Bot:
Use the Docker Compose file:
This builds the Docker images, starts the bot and PostgreSQL database, and runs them in detached mode (so they run in the background, even when you disconnect from the server).
Verify the Setup:
Check container status:
View logs:
The bot should appear online in your Discord servers. Run
/configin Discord to configure settings.
Initial Configuration in Discord:
Use slash commands like
/config sources-of-truthto set trusted users.Configure ban sync settings per server.
Step 4: Monitoring and Maintenance
Logs
View real-time logs:
Updates
Pull the latest code:
Restart:
Backups
Backup the database volume:
Remember to put in the values you have in your
.envfile!Store
backup.sqlsecurely (e.g., off-VPS).
Stopping the Bot
Restarting
Troubleshooting
Common Issues
Bot Not Starting: Check
.envfor errors. EnsureBOT_TOKENis valid and permissions are correct.Database Connection Failed: Verify
DATABASE_URLand that PostgreSQL is running (docker compose ps).Permissions Errors: Ensure the bot has
Ban MembersandView Audit Login all servers.Container Crashes: Use
docker compose logsto diagnose. Common causes: invalid env vars or port conflicts. If a container is stuck in a restart-loop (containers restart themselves if they fail) stop the containers withpnpm run docker:downand open a Github Issue so we can resolve this together.
Database Issues
If PostgreSQL fails to start, delete the volume and restart:
This deletes all data; use only if necessary.
Performance
For high-traffic servers, increase VPS resources.
Security Considerations
Environment Variables: Never commit
.envto Git (This is ensured by default with the.gitignorefile).Updates: Keep Docker and the system updated to patch vulnerabilities.
Access: Limit SSH access with key-based authentication. (For advanced users)
Additional Resources
The Repository: CrossBan on GitHub
If you encounter issues, check the repository's issues or logs for more details. Happy hosting!
Last updated
Was this helpful?