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

  1. Install Dependencies: Ensure all project dependencies are up-to-date.

    npm install
    
  2. Set Environment Variables: Configure your .env file with the production values:

    BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN
    CLIENT_ID=YOUR_DISCORD_CLIENT_ID
    
  3. Build the Bot: To be able to run the bot, you need to build it first:

    npm run build
    
  4. 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)

  1. Use a service like DigitalOcean, Linode, or AWS EC2 to set up a server.
  2. SSH into the server:
    ssh user@your-server-ip
    
  3. 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
    
  4. 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

  1. Go to Railway and create a new project.
  2. Link your GitHub repository.
  3. Add environment variables under Settings > Variables.
  4. Deploy the bot.

Heroku

  1. Install the Heroku CLI.
  2. Log in and create a new app:
    heroku login
    heroku create
    
  3. Add your environment variables:
    heroku config:set BOT_TOKEN=YOUR_BOT_TOKEN CLIENT_ID=YOUR_CLIENT_ID
    
  4. Push your code to Heroku:
    git push heroku main
    

4. Database Setup

  1. If using a cloud SQL provider (e.g., Supabase, Railway, AWS RDS), create a new database instance.
  2. Obtain your connection string and set it in your .env file under DATABASE_URL.
  3. 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! 🚀