Table of Contents
What you will read?
Running your own Discord bot on an ubuntu 25.04 server gives you full control, better uptime, and the ability to customize your bot however you want. By the end, your bot will be live and connected to your Discord server.
Step 1: Update Your Server
First, make sure your Ubuntu server is up to date. This ensures smooth installation of required packages:
sudo apt update && sudo apt upgrade -y
Step 2: Install Node.js and npm
Discord bots are most commonly built with Node.js, so install Node.js and npm (Node package manager):
sudo apt install nodejs npm -y
Check installation:
node -v
npm -v
Step 3: Create a Discord Application and Get a Token
- Go to the Discord Developer Portal.

- Create a New Application → Add a Bot inside it.
- Copy the Bot Token. This token will connect your script to Discord. Keep it private.
Step 4: Set Up Your Bot Project
Create a new folder for your bot and initialize it:
mkdir my-discord-bot && cd my-discord-bot
npm init -y
npm install discord.js
This installs discord.js, the official library for building Discord bots.
Step 5: Write the Bot Code
Create a file called bot.js:
nano bot.js
Paste this basic bot code:
const { Client, GatewayIntentBits } = require('discord.js');
const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
client.once('ready', () => {
console.log('Bot is online!');
});
client.on('messageCreate', message => {
if (message.content === '!ping') {
message.reply('Pong!');
}
});
Replace YOUR_BOT_TOKEN with the token you got from the Developer Portal.
Save and exit (CTRL+O, then CTRL+X).
Step 6: Run the Bot
Now that your bot script is ready, it’s time to bring it online. Running the file with Node.js will start the bot and connect it to Discord so you can interact with it directly:
node bot.js
Step 7: Keep the Bot Running
To ensure your bot keeps running after you close the terminal, use pm2:
sudo npm install -g pm2
pm2 start bot.js --name mydiscordbot
pm2 save
pm2 startup
This way, your bot will always restart automatically if the server reboots.
