Skip to content

Commit 0175589

Browse files
committed
Complete part 11
1 parent 8a9e571 commit 0175589

File tree

4 files changed

+276
-2
lines changed

4 files changed

+276
-2
lines changed

11 - Connect to DB/.env.example

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
TOKEN = YOUR_BOT_TOKEN
1+
TOKEN = YOUR_BOT_TOKEN
2+
MONGODB_URI = YOUR_MONGO_URI

11 - Connect to DB/package-lock.json

Lines changed: 261 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

11 - Connect to DB/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
"dependencies": {
1313
"discord.js": "^14.7.1",
1414
"dotenv": "^16.0.3",
15+
"mongoose": "^6.9.0",
1516
"ms": "^2.1.3",
1617
"pretty-ms": "^8.0.0"
1718
}

11 - Connect to DB/src/index.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
require('dotenv').config();
22
const { Client, IntentsBitField } = require('discord.js');
3+
const mongoose = require('mongoose');
34
const eventHandler = require('./handlers/eventHandler');
45

56
const client = new Client({
@@ -11,6 +12,16 @@ const client = new Client({
1112
],
1213
});
1314

14-
eventHandler(client);
15+
(async () => {
16+
try {
17+
mongoose.set('strictQuery', false);
18+
await mongoose.connect(process.env.MONGODB_URI, { keepAlive: true });
19+
console.log('Connected to DB.');
20+
21+
eventHandler(client);
22+
} catch (error) {
23+
console.log(`Error: ${error}`);
24+
}
25+
})();
1526

1627
client.login(process.env.TOKEN);

0 commit comments

Comments
 (0)