A customizable Discord bot based on discord.js v14 with Typescript!
-
Bring music to your servers with the included Discord player library!
-
Persist settings for each discord server/guild with MongoDB, managed by Prisma (code can be modified to use other databases supported by Prisma).
-
Easy troubleshooting with Winston logging.
-
Configure the bot with the
config.json
file. Real-time validation with AJV
- Install the following software.
-
Create your bot application on the Discord developer portal
- Refer to the discord.js guide for directions. Specifically: setting up your bot application and then adding it to server(s).
It is recommended to use separate discord bot applications for development and production. This is for security reasons and because it can be difficult to differentiate global commands from in development commands otherwise.
-
Setup your database of choice.
-
MongoDB is the default. You can easily set up a free instance with MongoDB Atlas.
-
If you want to use a different database, see here for databases supported by Prisma. This will also require some changes to
prisma/schema.prisma
.
-
-
Download this repository (clone/fork/raw download).
From here, follow the steps for your desired setup:
-
Rename
sample.development.env
todevelopment.env
and set the environment variables as defined insrc/global.d.ts
-
DISCORD_TOKEN
: Discord bot token (acquired in step 1). -
DB_URL
Database URL- Unless you modified
prisma/schema.prisma
to use a different type of database, this should be a MongoDB URL.
- Unless you modified
-
CLIENT_ID
Discord bot client ID (acquired in step 1). -
TEST_GUILD_ID
guild ID of the server you will use to test this bot.- Slash commands will immediately be updated for this server and this server only upon restarting the bot in developer mode.
-
DEV_IDS
A list of developer discord user IDs (must set at least one)- IDs should be separated by
", "
. Ex:DEV_IDS='DEV_ID1, DEV_ID2, DEV_ID3'
.
- IDs should be separated by
-
-
Run
npm ci
to do a clean install of dependencies and generate Prisma client files. -
Run
npm run dev
to start a developer environment instance!- Edit and save any of the files in the
src
directory (with the exception ofprisma/schema.prisma
) and the program will automatically restart to reflect the changes!
- Edit and save any of the files in the
-
Rename
sample.env
to.env
and set the environment variables as defined insrc/global.d.ts
-
DISCORD_TOKEN
: Discord bot token (acquired in step 1). -
DB_URL
Database URL- Unless you modified
prisma/schema.prisma
to use a different type of database, this should be a MongoDB URL.
- Unless you modified
-
CLIENT_ID
Discord bot client ID (acquired in step 1).
-
-
Run
npm ci
to do a clean install of dependencies and generate Prisma client files. -
Run
npm run build
to compile the source code for production.- If you are tight on storage space, delete the
node_modules
folder after runningnpm run build
. Then, runnpm ci --production
to install only the dependencies needed for production.
- If you are tight on storage space, delete the
-
Change the
config.json
file to your liking. See information about how you can change it here.This file is generated by the previous step.
-
If this is the first time you have run the bot or you are updating the source code, run
npm run commands:register
to register all your commands to any and all servers this bot is in. You may need to runnpm run commands:resetProd
prior tonpm run commands:register
if some old commands are not being removed. -
Run
npm start
to run the bot! -
[Optional] Add PM2 or containerize with Docker. Then, deploy to a cloud service (Heroku, Linode, Vultr, etc.) or on your own hardware.
-
name
: name of the bot (displayed in some commands). -
activities
: list of activities the bot will randomly cycle through as its current activity (Exs: "Watching The Fellowship of the Ring", "Listening to Never Gonna Give you Up", etc.).-
type
: integer that can only be one of the following values.0
= PLAYING1
= STREAMING2
= LISTENING3
= WATCHING4
= **NOT VALID, DO NOT USE**5
= COMPETING -
name
: string after thetype
.
-
I did not create the icons used. They are sourced from here under their license.