This is a template for building a Discord bot using the discord.js
, mongoose
libraries
Before you begin, make sure you have the following installed on your system:
- Node.js: version 16 or higher.
- npm: version 7 or higher.
- Clone or download this repository.
- Navigate to the root directory of the project and create a file called
.env
. - Follow the instructions below to get a Discord token and a MongoDB connection string.
- Copy the contents of
.env.example
into.env
and fill in the necessary values for your bot. - Install the required packages by running the following command:
npm i
- Complete the project using the commands below:
npm run build
npm run start
To use the Discord API, you need to create a Discord bot and get a token to authenticate your bot. Here's how to do that:
- Go to the Discord Developer Portal and log in with your Discord account.
- Click on the "New Application" button.
- Give your application a name and click "Create".
- On the left-hand side of the screen, click on the "Bot" tab.
- Click on the "Add Bot" button.
- Enable all intents on the Discord Developer Portal
- Go to the Discord Developer Portal.
- Go to the Discord Developer Portal.
- Click on the name of your Discord application.
- Click on the "Settings" tab.
- Scroll down to the "Privileged Gateway Intents" section.
- Click on the toggle switch next to each intent to enable it.
- Copy the token that is displayed on the screen. This is the token you will use to authenticate your bot.
To connect to a MongoDB database, you need a connection string that specifies the hostname and port of the MongoDB server, as well as the name of the database you want to connect to. Here's how to get a connection string:
- Sign up for a MongoDB Atlas account.
- Create a new cluster and select the "Free Tier" option.
- Click on the "Connect" button.
- Follow the instructions to connect to your cluster using the MongoDB Compass GUI.
- Click on the "Connect Your Application" button.
- Copy the connection string that is displayed on the screen. This is the connection string you will use to connect to your MongoDB database.