Skip to content

Installation

Bradford edited this page Jul 20, 2023 · 2 revisions

Getting Started

Clone this repo into your linux environment.

Requirements

  • docker

Step 1: Create a Discord Application on the Discord Developer Portal

Visit the Discord Developer Portal and create an application.

Make note of your:

  1. Application ID found under General Information
  2. Bot Token found under Bot

Optional: Create a Discord Server for Testing / Development

Create a private discord server to test the bot on.

Step 2: Authorize the Bot on your Server

To authorize the bot with the necessary permissions (Create commands in a server) to join your server, build the url as follows (taken from the discord.js guide):

https://discord.com/api/oauth2/authorize?client_id=<APPLICATION_ID>&permissions=0&scope=bot%20applications.commands

Step 3: Set up environmental variables

Copy .env.template to .env:

$ cp .env.template .env
$ vi .env

Fill in missing variables in .env, such as the Discord Token and App ID. Edit any others as desired. If you are deploying to a server, copy the server id to the DEV_GUILD_ID variable. The server id is found in Discord through these steps:

  1. Enable Developer Mode in the Discord App
  2. Right click on the server and select Copy ID

Step 4: Build the Docker Image

Run the following command to build an image from source:

$ docker compose build

Step 5: Publish the commands to your server

Use the discord-utils.js script to deploy the bot commands to your dev server or globally to all servers. You can either run the script in a container, or locally if you have node.js installed.

Using discord-utils.js in docker

Run this command to view the script options:

$ docker run --env-file .env -it xx-monitor-bot-bot node built/discord/discord-utils.js

Required: Deploy commands to server or globally

You may choose to deploy globally or to a specific server. Deploying globally allows users to interact with the bot over Direct Messages. Don't deploy to both, however, because the commands will appear multiple times in the Discord UI.

To deploy globally:

$ docker run --env-file .env -it xx-monitor-bot-bot node built/discord/discord-utils.js deploy --global

To deploy to a server:

$ docker run --env-file .env -it xx-monitor-bot-bot node built/discord/discord-utils.js deploy

To un-deploy:

$ docker run --env-file .env -it xx-monitor-bot-bot node built/discord/discord-utils.js --reset

To deploy changes you make to the SlashCommandBuilder object in your commands:

Just deploy as you originally did, either globally or to a server.

Update username

$ docker run --env-file .env -it xx-monitor-bot-bot node built/discord/discord-utils.js username "xx monitor bot"

Update avatar

$ docker run --env-file .env --volume <image path, e.g. ./image.jpg>:/image -it xx-monitor-bot-bot node built/discord/discord-utils.js avatar /image

Using bot-utils.js locally

Use the following commands to install the required packages and publish the slash commands to your server:

$ npm install
$ npm run build
$ node built/discord/discord-utils.js help
$ [... command output ...]

You can also set the bot username and status with the BOT_USERNAME and BOT_STATUS variables in .env and they will be set each time the bot starts.

Step 6: Start the Bot

Run the following command to start the bot in the background:

$ docker compose up -d

To view the logs of the running containers, try the following commands:

$ docker compose logs           # shows most recent logs from all containers
$ docker compose logs -f        # follows the log output of all containers continuously
$ docker compose logs -f bot    # follows the bot console continuously