Skip to content

Commit

Permalink
[New] Bots now looks for a mongodb database and connects to it, NIY
Browse files Browse the repository at this point in the history
  • Loading branch information
naseif committed Oct 3, 2021
1 parent ed92fcc commit c6fbbfe
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
const { Client, Collection, Intents } = require("discord.js");
const { logger } = require("./modules/logger.js");
const { token, prefix } = require("./config.json");
const { token, mongourl } = require("./config.json");
const { connectDatabase } = require("./modules/DatabaseConnection");
const { commandsHelper } = require("./modules/commandsHelper");

const client = new Client({
Expand All @@ -25,5 +26,7 @@ commandsHelper.registerAllCommands(__dirname + "/commands", client);
commandsHelper.registerAllEvents(__dirname + "/events", client);
playerEvents(client.player);

// Connect to DATABASE
connectDatabase(mongourl, client);
// ... and go!
client.login(token);
22 changes: 22 additions & 0 deletions modules/DatabaseConnection.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require("mongoose");

module.exports.connectDatabase = (mongourl, client) => {
const dbOptions = {
useNewUrlParser: true,
autoIndex: false,
connectTimeoutMS: 10000,
family: 4,
useUnifiedTopology: true,
};
mongoose.connect(mongourl, dbOptions);
mongoose.Promise = global.Promise;
mongoose.connection.on("connected", () => {
client.logger("[DB] DATABASE CONNECTED");
});
mongoose.connection.on("err", (err) => {
console.log(`Mongoose connection error: \n ${err.stack}`, "error");
});
mongoose.connection.on("disconnected", () => {
console.log("Mongoose disconnected");
});
};

0 comments on commit c6fbbfe

Please sign in to comment.