3v-Hosting Blog

How To Set Up a Discord Server on VPS

Administration

8 min read


Discord is no longer just a platform for gamers. Over the years, it has evolved into a full-fledged ecosystem for communities, development teams, startups, and online education. It supports everything - from casual chats to complex bot automation and server-based integration with external systems. Setting up your own Discord server on a VPS gives you full control over its performance, availability, and customization - something that traditional shared hosting or free Discord setups can’t offer. Let’s walk through the process step by step.

 

 

 

 

Why Host a Discord Server on VPS

 

At first glance, Discord is a cloud service that “just works” - you sign up, create a server, and invite your friends. But advanced users often want more: custom bots, private integrations, event automation, or even a proxy layer to manage communication between external services. Hosting these components on a VPS (Virtual Private Server) gives you stability, flexibility, and freedom from the platform’s limitations.

A VPS offers dedicated CPU, RAM, and storage resources - isolated from other users. That means your Discord-related services (bots, webhooks, music players, or analytics scripts) can run 24/7 without downtime or throttling. It’s also easier to deploy additional software - for example, Node.js for bot logic, Docker for containerized deployments, or Nginx as a reverse proxy for web dashboards.

 

 

 

 

Choosing the Right VPS Configuration

 

Before setting up anything, pick a VPS configuration that matches your goals. For a simple Discord bot, 1 vCPU and 512 MB of RAM is usually enough. But if you plan to run multiple bots, host media files, or integrate APIs with databases, aim for at least 2 vCPUs and 2 GB RAM.

Operating system choice matters too. Most developers prefer Ubuntu 22.04 LTS or Debian 12, because of their stability and broad community support. Both work perfectly with Discord’s API libraries and popular programming environments like Python or Node.js.

When choosing your hosting provider, prioritize low latency, SSD storage, and stable connectivity - especially if your server will stream audio or handle large-scale events.

 

 

 

 

Step 1: Setting Up the Environment

 

After purchasing a VPS, connect via SSH:

    ssh root@your-server-ip


Update the system and install the essential packages:

    apt update && apt upgrade -y
    apt install git curl build-essential -y


Next, install Node.js - the most common platform for developing and running Discord bots.

    curl -fsSL https://deb.nodesource.com/setup_lts.x | bash -
    apt install -y nodejs


Check the version:

    node -v
    npm -v


If you plan to run multiple bots or keep them persistent, install PM2, a process manager for Node.js applications:

    npm install pm2 -g

 

 


 

Other interesting articles in our Blog:


    - How to Create a Discord Bot

    - How to Install Node.js on Ubuntu 22.04

    - How to open a port in UFW

    - VPS performance problems or Why is my server slow?

 


 

 

Step 2: Creating a Discord Bot

 

Log in to your Discord account and visit the Discord Developer Portal. Click “New Application,” give it a name, then go to the Bot tab and press “Add Bot.” Copy the token - this will be your bot’s authentication key.

Never share your token publicly. Treat it like a password.

Create a new directory for your bot and initialize a Node.js project:

    mkdir discord-bot && cd discord-bot
    npm init -y
    npm install discord.js


Now create a simple bot file:

    nano index.js


Paste the following minimal example:

    const { Client, GatewayIntentBits } = require('discord.js');
    const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });

    client.on('ready', () => {
      console.log(`Logged in as ${client.user.tag}!`);
    });

    client.on('messageCreate', message => {
      if (message.content === '!ping') {
        message.reply('Pong!');
      }
    });

    client.login('YOUR_BOT_TOKEN');


Save the file and start your bot:

    node index.js


If you see “Logged in as [bot name]!”, congratulations - your bot is alive.

 

 

 

 

Step 3: Running the Bot 24/7

 

Manually starting the bot isn’t practical - it would stop after you log out or restart the VPS. That’s where PM2 helps.

From your bot directory, run:

    pm2 start index.js --name discord-bot
    pm2 save
    pm2 startup


The last command will output a systemd command - copy and execute it so PM2 starts automatically on reboot.

You can monitor logs anytime:

    pm2 logs discord-bot


Now your bot runs continuously in the background, even if the VPS restarts.

 

 

 

 

Step 4: Securing and Optimizing the VPS

 

Security is critical when you expose any service online. Start by setting up a non-root user and enabling a firewall:

    adduser discordadmin
    usermod -aG sudo discordadmin
    ufw allow ssh
    ufw enable


You can also enable automatic updates:

    apt install unattended-upgrades
    dpkg-reconfigure unattended-upgrades


To avoid leaks, store the bot token and other secrets in environment variables instead of hardcoding them:

    export DISCORD_TOKEN="your-token"


Then, modify your bot to read it dynamically:

    client.login(process.env.DISCORD_TOKEN);


This way, your code remains secure even if published to GitHub or shared with collaborators.

 

 

 

 

Step 5: Scaling and Monitoring

 

When your project grows, you may want to host multiple bots or integrate databases like PostgreSQL or Redis for persistent data. This is where the true power of VPS shines.

You can use Docker Compose to run different services in isolated containers - a web dashboard in one, your bot logic in another, and Redis as a cache layer. Tools like Prometheus and Grafana can track your server’s CPU, memory, and API response times, providing real visibility into performance.

For high availability, consider running bots across multiple VPS instances with load balancing. Platforms like HAProxy or Nginx can distribute requests efficiently.

 

 

 

 

Troubleshooting Common Issues

 

Bot not responding? Check the bot’s token and permissions - it must have the “MESSAGE CONTENT INTENT” enabled in the Developer Portal.

Connection timeouts? Ensure your firewall allows outgoing HTTPS connections to Discord’s API endpoints.

Memory leaks? Use PM2’s monitoring (pm2 monit) to identify resource-hungry processes. Sometimes updating the discord.js library resolves instability.

 

 

 

 

The Freedom of Self-Hosting

 

Running a Discord server on VPS is not just about having control - it’s about independence. You decide when to update, what features to deploy, and how far to scale. It’s your private corner of the digital world, running on your rules.

With the right VPS configuration, even a small project can evolve into a full-fledged automation hub, handling hundreds of servers and thousands of users. And the best part? You’re no longer bound by someone else’s limitations - your creativity becomes the only boundary.

In summary, setting up a Discord server on a VPS combines the best of both worlds: Discord’s versatile communication platform and the flexibility of a dedicated environment. Whether you’re running a community, building tools for developers, or experimenting with automation - the setup pays off. Once your VPS is configured, the rest is pure fun: experimenting, building, and seeing your digital world come alive.