This repository houses the "contrabot", a Discord bot for Contraversum, developed using Node.js, TypeScript, and discord.js.
Before you begin, make sure you have the following installed:
- Node.js
- MongoDB (especially if you're using the
mac-start
script) - TypeScript - You can also install this using npm:
npm install -g typescript
-
Clone the Repository
git clone https://github.com/Contraversum/ContraBot/issues cd contrabot
-
Install Dependencies
After navigating into the repository directory, install the necessary packages:
npm install
-
Managing the Discord Bot Token
For the bot to interact with Discord, it requires a secret bot token provided by the Discord developer portal. This token acts as a unique identifier and a password for your bot, granting it various permissions, so it should be kept confidential.
Getting the Token: If you're setting up the bot for the first time or wish to run a local instance, you'll need to obtain a bot token:
Visit the Discord Developer Portal. Navigate to the "Bot" tab . Under the "TOKEN" section, click "Copy" to get your bot token. Setting Up the Token Locally:
Create a '.env' file in the root directory of the project. Inside the config file, set your token like this: token:"XXX". If you suspect your bot token has been compromised, go back to the Discord Developer Portal and regenerate the token immediately. Along with the Token you will need to set up the other secrets that can be found in the moderator channel of the Contraversum Discord server.
You will need to join the ContraversumTest Discord Server. Here you will find the production bot. You can access the production bot by creating a branch from the 'pre-production' branch and altering the .env file. With the secrets that can be found in the moderator channel of the Contraversum Discord server.
The production bot uses a MongoDB database. You can set up a MongoDB database using the following steps:
- Install MongoDB https://www.mongodb.com/docs/manual/administration/install-community/
- Create a database called 'contrabot'
- Create a collection called 'users'
You can access the live database using the following steps:
-
Start the Bot
To run the bot in a standard environment:
npm run start
If you are on macOS and want to start MongoDB along with the bot:
npm run mac-start
Note: The
mac-start
script assumes you have MongoDB installed via Homebrew and the respective service namedmongodb-community@7.0
.If you are on GNU/Linuxand want to start MongoDB along with the bot you can use one of the follownig commands:
npm run systemd-start
or (depending if your OS uses systemd or System V Init)
npm run systemv-start
Note: The
systemd-start
andsystemv-start
script assumes you have MongoDB installed using the package manager.
-
TypeScript Compilation
This project uses
ts-node
to directly run TypeScript, so you don't need to compile it separately. However, if you want to generate JavaScript files, you can set up atsc
script or runtsc
directly.
With these steps, you should be set up to develop and test the Contrabot. Always ensure to follow best practices and update dependencies as necessary to keep the bot secure and efficient.