Discord Bot for the mobile MMO game Star Trek Fleet Command, providing your alliance with an interactive scoring system using the game's player statistics, plus a whole host of alliance-related features.
This Bot uses DiscordJS - An object-oriented node.js wrapper for the official Discord API.
- nodejs (https://nodejs.org/en/download/)
- Postgres (https://www.postgresql.org/download/)
- A valid discord user token (https://discordapp.com/developers/applications/me)
Postgres need not be running on target machine, and there are many free hosting options. MrData can be configured to work with any Postgres database, locally or in the cloud.
Note: This installation guide will not take you through the process of using the Discord developer portal to obtain a valid token and connect the bot to a server. If the portal seems complicated, there are plenty of idiot's guides and how-to's that will take you through this process, step-by-step.
Once you have installed node on your development machine (and the production environment), there are various node.js dependancies that need to be installed via a shell window, using the npm
package manager and the project packages.json
file.
- Set up node
- Configure postgres
- Obtain a discord application token
- Modify
config-secret.json
- Run the bot.
The project dependancies can be installed using the command
npm install
Note: please see the section below for instructions on updating the dependancies to the latest versions and simultaneously updating packages.json
to reflect these changes.
- Although
npm update
will update all modules present inpackage.json
to their latest versions, the changes will not automatically be applied back topackage.json
!
Existing behaviour: npm update
installs the latest versions of modules from the npm repositories while respecting the caret and tilde dependencies specified in the package.json file. Although the modules are updated to the latest versions, the versions mentioned in the package.json
file are not changed. This leads to confusion, since it creates a mismatch between the installed versions in node_modules
repository and the (now older) versions mentioned in package.json file.
There is a fix: To ensure you update to the latest version and update the package.json to reflect the changes, perform the following steps using a shell window:
- Install the
ncu
utility globally:
npm install –g npm-check-updates
This can be invoked with the command ncu
.
Nb: ncu
is a short form of npm-check-updates, and displays the output without actually performing any changes.*
- Update the package.json file, as per latest versions available from the npm repositories on web:
ncu –u
- Finally, update the local node_modules repository with the versions present in package.json, as you would do normally. But now, Both the
package.json
and the localnode_modules
repository are updated to the latest versions available on web.
npm install
This guide is not going to take you through the steps to setup your own Postgres database. You can either download and run the postgres server on your machine(s), or use a free host. If you're unsure about setting up the software on your own machine, or are wary of opening ports, then use a free hosting service.
Take a note of the following information:
- database URL, e.g. somewebservice.org.uk
- port (usually 5432)
- username
- password
- Database name
Note: Postgres databases can be connected to via a long URL, of the form postgres://username:password@localhost:5432/databasename', but we will not be using such a connection string.
Instead, we will specify this informmation in the config-secret.json
file.
You must register your bot in order to use the discord API. You do this via the discordapp.com developer application portal.
A simple internet search reveals a large quantity of tutorials. Take a note of the discord application token.
With all the information you have taken a note of, it's time to edit the config-secret.json
file. The file will look something like this:
{
"db": {
"host": "clamtastic.hopto.org",
"port": 2345,
"database": "postgres",
"user": "postgres",
"password": "postgres",
"max": 5,
"idleTimeoutMillis": 5000
},
"token": "ABCDEFGHIJKLMNOPQRSTUVWXYZ.abcdefghijklmnopqrstuvwxyz"
}
The additional parameters can be tweaked by you. For example, although the default numnber of concurrent connections in pg-promose is 10, the maximum for https://www.elephantsql.com/ is 5.
You have joined it to your server already, haven't you!? Simply open your shell, navigate to the project directory, and type:
node bot.js