Initial bot configuration
Useful info
It is recommended to edit .js
files with a text editor, I strongly recommend Visual Studio Code
which is completely free and open-source. For Linux you can download the binary from the VSCode website if available or download your distribution's package accordingly.
Editing the config file
The application's token
Setting up galactica is quite an easy process, and it is required to do it before starting the bot for the first time.
First we need to export the GALACTICA_TOKEN
environment variable, this is the token that you got from the Discord Developer Portal when you created your bot application.
On UNIX-based
systems you can do this by editing your
.bashrc
file and adding the following line on Windows you need to set the environment variable in the system settings.
export GALACTICA_TOKEN="your-token-here"
Now all we need to do is to save the file and restart your shell, you can do this by running source ~/.bashrc
or by simply opening a new terminal,
for Windows users a restart is required to refresh the environment variables.
The presence status
The second step of the configuration is to set the presence status of the bot, this is done by editing the presence
properties in the config.js
file.
const { ActivityTypes } = require("discord.js");
module.exports.config = {
BOT_PRESENCE: "YOUR_BOT_PRESENCE",
BOT_PRESENCE_TYPE: ActivityTypes.Watching
}
Configuration parameters
Environment variables
Variable | type | Default | Description |
---|---|---|---|
TOKEN | string | no | The bot's token, if you don't have one you can get one from the Discord Developer portal . |
DATABASE_URL | string | no | The connection string or the file pointing to your SQL database. |
Config file
Variable | type | Default | Description |
---|---|---|---|
BOT_PRESENCE | string | null | Sets the rich presence shown on the bot |
BOT_PRESENCE_TYPE | Discord#ActivityTypes | ActivityType#Watching | Sets the presence type of the bot. https://discord-api-types.dev/api/discord-api-types-v10/enum/ActivityType |
Configuring the database
Galactica works with a SQL
database, you can use any database that is supported by Prisma,
but it is recommended to use PostgreSQL
or MySQL
as they are the most stable and performant.
Setting the environment variable
Another environment variable that we need to export is DATABASE_URL
, this is the URL to your database, you can use a local database or a remote one, it's up to you.
For any SQL database, you can use the following line to specify your db's url:
- SQLite
- Remote DB
export DATABASE_URL="file:./galactica.db"
export DATABASE_URL="provider://username:password@host:port/database"
After exporting the variable you must restart your shell or restart your computer for the changes to take effect.
Using external databases
Due to Galactica using the Prisma Object Relational Mapper, it supports most SQL
database with little to minimal configuration,
to change the default database edit the .env
file. To use a different database you must edit the prisma/schema.prisma
file.
Most of the time you just need to change the provider field but for more info visit prisma docs.
generator client {
provider = "prisma-client-js"
}
datasource db {
provider = "YOUR_DATABASE_PROVIDER"
url = env("DATABASE_URL")
}
model GuildConfigs {
id Int @id @default(autoincrement())
guildID String @unique
guildName String
dateJoined DateTime @default(now())
modLogsIsEnabled Boolean @default(false)
modLogsChannelID String? @unique
@@index([guildID])
}
Pushing Prisma queries to database
Now we need to push the changes to the database and generate the according prisma client types, to do so run:
- npx
- yarn
- pnpx
npx prisma db push
yarn prisma db push
pnpx prisma db push
Note for planetscale users
If using planetscale prisma does require some extra configuration the first part which is the schema file is already covered
by galactica-bot, and it's located in prisma/schema.planetscale.prisma
. The db push
command won't work though because
it doesn't know where the schema is located,
thankfully galactica includes a package.json script which points to the planetscale schema 🥳, to use it just run:
- npm
- yarn
- pnpm
npm run prisma:planetscale
yarn prisma:planetscale
pnpm prisma:planetscale
Note for docker users
The Dockerfile
does not have great support for database connections at the mean time, you can run the bot in hardware.