|
| 1 | + |
| 2 | +# Deployment Guide |
| 3 | + |
| 4 | +Follow this guide to deploy your **Discord.js Giveaway Bot** to a production environment. This ensures your bot runs reliably 24/7. |
| 5 | + |
| 6 | +## 1. Prerequisites |
| 7 | + |
| 8 | +Before deploying, ensure the following: |
| 9 | + |
| 10 | +- **Bot Token** and **Client ID** from the [Discord Developer Portal](https://discord.com/developers/applications). |
| 11 | +- A cloud hosting service or server (e.g., **VPS**, **Heroku**, **Railway**, or **AWS**). |
| 12 | +- **Node.js** (v16 or later) and **npm** installed on your server. |
| 13 | + |
| 14 | +## 2. Preparing the Bot for Production |
| 15 | + |
| 16 | +1. **Install Dependencies**: Ensure all project dependencies are up-to-date. |
| 17 | + ```bash |
| 18 | + npm install |
| 19 | + ``` |
| 20 | + |
| 21 | +2. **Set Environment Variables**: Configure your `.env` file with the production values: |
| 22 | + ```bash |
| 23 | + BOT_TOKEN=YOUR_DISCORD_BOT_TOKEN |
| 24 | + CLIENT_ID=YOUR_DISCORD_CLIENT_ID |
| 25 | + ``` |
| 26 | + |
| 27 | +3. **Build the Bot**: To be able to run the bot, you need to build it first: |
| 28 | + ```bash |
| 29 | + npm run build |
| 30 | + ``` |
| 31 | + |
| 32 | +4. **Test Locally**: Run the bot to ensure no errors occur: |
| 33 | + ```bash |
| 34 | + npm start |
| 35 | + ``` |
| 36 | + |
| 37 | +## 3. Deploying to a Server |
| 38 | + |
| 39 | +### Option 1: Using a Virtual Private Server (VPS) |
| 40 | +1. Use a service like **DigitalOcean**, **Linode**, or **AWS EC2** to set up a server. |
| 41 | +2. SSH into the server: |
| 42 | + ```bash |
| 43 | + ssh user@your-server-ip |
| 44 | + ``` |
| 45 | +3. Install Node.js and clone your project repository: |
| 46 | + ```bash |
| 47 | + sudo apt update |
| 48 | + sudo apt install nodejs npm |
| 49 | + git clone https://github.com/YourUsername/DiscordGiveawayBot.git |
| 50 | + cd DiscordGiveawayBot |
| 51 | + npm install |
| 52 | + ``` |
| 53 | +4. Add your `.env` file and start the bot: |
| 54 | + ```bash |
| 55 | + npm start |
| 56 | + ``` |
| 57 | + |
| 58 | +To keep the bot running continuously, use **PM2**: |
| 59 | +```bash |
| 60 | +npm install -g pm2 |
| 61 | +pm2 start npm --name giveaway-bot -- start |
| 62 | +pm2 save |
| 63 | +pm2 startup |
| 64 | +``` |
| 65 | + |
| 66 | +### Option 2: Deploying on Railway or Heroku |
| 67 | + |
| 68 | +#### Railway |
| 69 | +1. Go to [Railway](https://railway.app) and create a new project. |
| 70 | +2. Link your GitHub repository. |
| 71 | +3. Add environment variables under **Settings > Variables**. |
| 72 | +4. Deploy the bot. |
| 73 | + |
| 74 | +#### Heroku |
| 75 | +1. Install the [Heroku CLI](https://devcenter.heroku.com/articles/heroku-cli). |
| 76 | +2. Log in and create a new app: |
| 77 | + ```bash |
| 78 | + heroku login |
| 79 | + heroku create |
| 80 | + ``` |
| 81 | +3. Add your environment variables: |
| 82 | + ```bash |
| 83 | + heroku config:set BOT_TOKEN=YOUR_BOT_TOKEN CLIENT_ID=YOUR_CLIENT_ID |
| 84 | + ``` |
| 85 | +4. Push your code to Heroku: |
| 86 | + ```bash |
| 87 | + git push heroku main |
| 88 | + ``` |
| 89 | + |
| 90 | +## 4. Database Setup |
| 91 | + |
| 92 | +1. If using a cloud SQL provider (e.g., **Supabase**, **Railway**, **AWS RDS**), create a new database instance. |
| 93 | +2. Obtain your **connection string** and set it in your `.env` file under `DATABASE_URL`. |
| 94 | +3. Run migrations or initialize the database if required. |
| 95 | + |
| 96 | +## 5. Monitoring and Logs |
| 97 | + |
| 98 | +To monitor your bot and check for issues: |
| 99 | + |
| 100 | +- **PM2**: Use `pm2 logs` to view live logs. |
| 101 | +- **Heroku**: Use `heroku logs --tail` to monitor logs in real time. |
| 102 | +- **Railway**: View logs in the Railway dashboard. |
| 103 | + |
| 104 | +## 6. Keeping the Bot Online |
| 105 | + |
| 106 | +If deploying to a VPS, ensure the bot restarts automatically after downtime: |
| 107 | + |
| 108 | +- Use **PM2** or **systemd** for process management. |
| 109 | +- Regularly monitor your server's health. |
0 commit comments