This bot is meant to be an example of how to use Discord.py to interact with a MongoDB database.
- Python
- A basic understanding of MongoDB and databases
- Know how to use a keyboard
- Go to the Discord Developer Portal and create a bot.
- Clone the repository
- Create a venv and use
pip
to installdiscord.py
andpymongo
. - Paste the token in
botToken
- Go to mongodb.com and sign up for a free tier account.
- Create a shared database
- Change the region to one hosted near where your bot is hosted.
- Set your username and password. Make note of them because you will need them. Do not include special characters like @, /, and \ in the password.
- Add your IP address to the access list. If you are hosting with a VPS or other service, you need to add their IP address. Please turn off your VPN for this step.
- When your database is created, click
Browse Collections
- Click
Add My Own Data
and enter your desired database and collection name. This bot usesScores
andscoreCounter
. - Now, MongoDB will be connected to the bot. In the sidebar, click
Database
and clickConnect
in the main screen. - Click
Connect your application
and copy the link. - In
main.py
, add the URL you copied to thecluster
variable. - Change
<password>
to the one you made note of in the beginning (not your MongoDB account password).