Deployment Guide
Follow this guide to deploy your Discord.js Giveaway Bot to a production environment. This ensures your bot runs reliably 24/7.
1. Prerequisites
Before deploying, ensure the following:
- Bot Token and Client ID from the Discord Developer Portal.
- A cloud hosting service or server (e.g., VPS, Heroku, Railway, or AWS).
- Node.js (v16 or later) and npm installed on your server.
2. Preparing the Bot for Production
-
Install Dependencies: Ensure all project dependencies are up-to-date.
npm install
-
Set Environment Variables: Configure your
.env
file with the production values:BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN CLIENT_ID=YOUR_DISCORD_CLIENT_ID
-
Build the Bot: To be able to run the bot, you need to build it first:
npm run build
-
Test Locally: Run the bot to ensure no errors occur:
npm start
3. Deploying to a Server
Option 1: Using a Virtual Private Server (VPS)
- Use a service like DigitalOcean, Linode, or AWS EC2 to set up a server.
- SSH into the server:
ssh user@your-server-ip
- Install Node.js and clone your project repository:
sudo apt update sudo apt install nodejs npm git clone https://github.com/ResyncedDesign/GiveawayBot.git cd GiveawayBot npm install npm run build
- Add your
.env
file and start the bot:npm start
To keep the bot running continuously, use PM2:
npm install -g pm2
pm2 start npm --name giveaway-bot -- start
pm2 save
pm2 startup
Option 2: Deploying on Railway or Heroku
Railway
- Go to Railway and create a new project.
- Link your GitHub repository.
- Add environment variables under Settings > Variables.
- Deploy the bot.
Heroku
- Install the Heroku CLI.
- Log in and create a new app:
heroku login heroku create
- Add your environment variables:
heroku config:set BOT_TOKEN=YOUR_BOT_TOKEN CLIENT_ID=YOUR_CLIENT_ID
- Push your code to Heroku:
git push heroku main
4. Database Setup
- If using a cloud SQL provider (e.g., Supabase, Railway, AWS RDS), create a new database instance.
- Obtain your connection string and set it in your
.env
file underDATABASE_URL
. - Run migrations or initialize the database if required.
5. Monitoring and Logs
To monitor your bot and check for issues:
- PM2: Use
pm2 logs
to view live logs. - Heroku: Use
heroku logs --tail
to monitor logs in real time. - Railway: View logs in the Railway dashboard.
6. Keeping the Bot Online
If deploying to a VPS, ensure the bot restarts automatically after downtime:
- Use PM2 or systemd for process management.
- Regularly monitor your server's health.
Now your bot should be online 24/7! 🚀