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 highly recommended to use separate discord bot applications for development and production. It can be difficult to differentiate global (production) commands from guild (development) commands in the discord client.
-
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/copy
sample.dev.env
todev.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.
-
-
Run
npm i
to install dependencies and generate Prisma client files. -
Run
npm run dev
to start a developer environment instance!-
Running this for the first time will generate
config.dev.json
if not present. -
Edit and save any of the files in the
src
directory and the development environment will automatically restart to reflect the changes!
-
-
Rename/copy
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 i
to install dependencies and generate Prisma client files. -
Run
npm run build
to transpile the source code for production.-
Running this for the first time will generate
config.json
if not present. -
If this is the first time you have run the bot or you are updating the source code, run
npm run commands:register
after transpilation 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 (Discord states that their servers can take up to an hour to reflect these changes. In experience this takes only a couple minutes).
-
-
With transpilation complete, you can now delete the
node_modules
folder. Then, runnpm ci --production
to install only the dependencies needed for production, omitting the dependencies only needed for transpilation/development.- Changing/updating any files other than
.env
orconfig.json
will require you to redo steps 6 and 7.
- Changing/updating any files other than
-
Change the
config.json
file to your liking. See information about how you can change it here. -
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.).-
name
: string after thetype
. -
type
: string that can only be one of the following values (case-sensitive).-
playing
= Playingname
-
streaming
= Streamingname
-
listening
= Listening toname
-
watching
= Watchingname
-
competing
= Competing inname
-
-
url
: (optional) url link to stream. Only include whentype
isstreaming
.
-
I did not create the icons used. They are sourced from here under their license.