A bot created for the Lospec Discord server, with the source made available for community contributions or for learning to make your own similar bot.
This is version 4, rewritten from the ground up to use the latest version of discord.js and node modules.
Not all of the functionality from version 3 has been ported over, and the bots are both run concurrently.
- Fork this project on Github
- Locally clone from your fork.
- In a the project working directory run
npm install
to download the required nodeJS modules - (Optional) Configure your local git repo to have the original repository as
upstream
so you can directly pull from it
Make sure you have a discord server set-up where you have admin permissions before following these steps
- Enter the Discord Developer Portal and create a
New Application
. This will be your testing application. - With the Application created, select the
Bot
tab from the left panel. ChooseAdd bot
. - Under the username, there will be a section labelled
token
, copy this to your clipboard - Create a file called
.env
on the root of the project - Add
DISCORD_BOT_TOKEN=
to the file, then paste the token afterwards and save
If you have access to a mongodb database, you can set it up to match the production database, or you instead use the local datastore option which just uses .json files.
- Create a MongoDB database
- Download your certificate and save it to
ca-certificate.crt
- Add
MONGO_URI=
to the .env file with your connection string, and append&tlsCAFile=ca-certificate.crt
to the end - Add
DB=LospecBotV4
to the .env file - Run the bot and it will automatically create the necessary tables and documents and the appropriate values
- Edit the documents to fill in any blank values
- Reboot the bot
Please note, if you update these documents manually by editing them, you must reboot the bot immediately for the changes to be recognizes. The data is stored in memory and overwrites the document whenever it's changed.
If you don't have access to a mongodb database, or find it too confusing to set up (understandably), you can just use the local option:
- Add
LOCAL_DATA_STORAGE=true
to the .env file - Run the bot, and it will automatically create a
./_data
folder and the necessary .json files - Edit the documents to fill in any blank values
- Reboot the bot
Please note, if you update these files manually by editing them, you must reboot the bot immediately for the changes to be recognizes. The data is stored in memory and overwrites the file whenever it's changed.
To run the bot, run the command npm start
from the command line from the project root.
How to expand the bot with new functionality.
Create a command that users can trigger
Add a file to the ./commands
folder with the following exports:
config
- an object containing the JSON configuration for a commandexecute
- an async function that is called when the function is run (passes interaction as first argument)
Respond to a message that matches a filter
Add a file to the ./responses
folder with the following exports:
filter
- an async function that checks if the message should trigger a responseexecute
- an async function that is called when the filter matches
To run the bot, you must have set up one of the two data storage options, explained above. Both options have identical APIs.
First you must import the appropriate document from the data module:
import {CONFIG} from '../data.js';
Modules that use a lot of properties should be set up with their own data store, which is defined in the data module:
export const MYDATAMODULENAME = new Data('my-data-module-slug');
- .get(
<string>
key ) - Get the value associated with the provided key - .set(
<string>
key,<any>
value ) - Set the value of the provided key to the provided value - .assert(
<string>
key,<bool>
required [optional] ) (async) - Ensure a value exists in the data store, and if not, create a blank value and throw an error (unless required is set to false). Must be awaited. This gives the developer a place to enter the value manually.