Skip to content

Instantly share code, notes, and snippets.

@JamalLyons
Last active May 12, 2022 12:30
Show Gist options
  • Save JamalLyons/42a65ede25b5da6d84c04eada89d12ff to your computer and use it in GitHub Desktop.
Save JamalLyons/42a65ede25b5da6d84c04eada89d12ff to your computer and use it in GitHub Desktop.
How to run a discord bot on a Linux server (ubuntu)

Activating root user (ubuntu):

Dont do this if your already in sudo or else the script may have errors

sudo su -

installing nodejs on ubuntu linux:

apt update -y && curl -fsSL https://deb.nodesource.com/setup_17.x | sudo -E bash - && apt install -y nodejs

Installing redis server

curl -fsSL https://packages.redis.io/gpg | sudo gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg

echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" | sudo tee /etc/apt/sources.list.d/redis.list

sudo apt-get update
sudo apt-get install redis

Commands

redis-cli ping

set <>

get <>

Creating new dir

mkdir bot

Cloning code

git clone https://github.com/yourname/yourrepo bot

Config

Depending on how you make your bot, you may or maynot have a config file for it. Make sure to fill this out using nano or vim or something else then compile your bot (if ts).

Install pm2

npm i -g pm2

Run the bot

make sure your in the backend folder.

npm run build && pm2 start ./out/registry.js --name "bot"

PM2 Commands

remember you can change the 0 with your pm2 process id

lists all commands

pm2 list

shows the logs for our node process [0]

pm2 logs 0 

restarts the node process

pm2 restart 0

stops the node process

pm2 stop 0

Linux terminal utils

delete a file

rm <file-name>

By default, rm only deletes files, so you need to tell it to delete a directory using -d, like this:

rm -d <folder>

Delete a folder with sub folders

rm -dr <dir>

Error fixing

You may see this error: image It means your missing some c++ build tools on your os. Install them using this command:

sudo apt-get install build-essential libcairo2-dev libpango1.0-dev
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment