Skip to content

Commit

Permalink
Complete part 11
Browse files Browse the repository at this point in the history
  • Loading branch information
notunderctrl committed Jan 30, 2023
1 parent 8a9e571 commit 0175589
Show file tree
Hide file tree
Showing 4 changed files with 276 additions and 2 deletions.
3 changes: 2 additions & 1 deletion 11 - Connect to DB/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
TOKEN = YOUR_BOT_TOKEN
TOKEN = YOUR_BOT_TOKEN
MONGODB_URI = YOUR_MONGO_URI
261 changes: 261 additions & 0 deletions 11 - Connect to DB/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions 11 - Connect to DB/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"dependencies": {
"discord.js": "^14.7.1",
"dotenv": "^16.0.3",
"mongoose": "^6.9.0",
"ms": "^2.1.3",
"pretty-ms": "^8.0.0"
}
Expand Down
13 changes: 12 additions & 1 deletion 11 - Connect to DB/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require('dotenv').config();
const { Client, IntentsBitField } = require('discord.js');
const mongoose = require('mongoose');
const eventHandler = require('./handlers/eventHandler');

const client = new Client({
Expand All @@ -11,6 +12,16 @@ const client = new Client({
],
});

eventHandler(client);
(async () => {
try {
mongoose.set('strictQuery', false);
await mongoose.connect(process.env.MONGODB_URI, { keepAlive: true });
console.log('Connected to DB.');

eventHandler(client);
} catch (error) {
console.log(`Error: ${error}`);
}
})();

client.login(process.env.TOKEN);

0 comments on commit 0175589

Please sign in to comment.