Getting Started
Discord bot user requires websocket connection, therefore modern serverless approach won’t apply here. You will need a virtual machine to self host your bot.
Requirements
Software
Node.js >= 16npm >= 9pm2(optional)
Hardware
CPU >= 1GHzRAM >= 512MB
Installation
Clone the repository
git clone https://github.com/xuc323/discord-botInstall dependencies
cd discord-bot
npm installConfigurations
Create a .env file in the root directory of the project and fill in the following fields:
# .env
DISCORD_TOKEN=YOUR_TOKEN
DATABASE_URL=POSTGRES_DATABASE_URL
PREFIX=!Format for DATABASE_URL. Here we are using postgresql as our database:
postgres://{user}:{password}@{host}:{port}/{database}Run the bot
npm run build
npm run startCleanup
npm run cleanpm2 (optional)
Bot will be terminated when you close the terminal. To keep the bot running in the background, you can use a node runtime such as pm2 to manage the process.
pm2 start npm --name "discord-bot" -- run startFor easier startup, you can also create a ecosystem.config.js file in the root directory of the project and fill in the following fields:
module.exports = {
apps: [
{
name: "discord-bot",
script: "npm",
args: "run start",
time: true,
},
],
};Then you can start the bot with:
pm2 start ecosystem.config.jsOr if you have a few apps within the same file:
pm2 start ecosystem.config.js --only discord-bot