title: Connect discord bot to mongo DB with event handler
body: <p>I am building a discord bot, and I'm trying to connect it to a mongo DB.</p>
  <p>The way my code is structured, I have a 'main' file, called index.js, where I run my main code, on the main code, I handle the events. Inside the event 'on ready'(which is executed once) I connect to the DB. This is how I handle the events on index.js:</p>
  <pre><code>for (const file of eventFiles) {
  const event = require(`./events/${file}`);
  if (event.once) {
      client.once(event.name, (...args) =&gt; event.execute(...args, commands));
  } else {
      client.on(event.name, (...args) =&gt; event.execute(...args, commands));
  }
  </code></pre>
  <p>}</p>
  <p>To connect to the DB, I have an event script, called ready, that is called only once. The problem I'm having is, when I try to connect to the DB, I get stuck without a response. I'm using <a href="https://mongoosejs.com/docs/index.html" rel="nofollow noreferrer">mongoose js</a> and following their documentation to connect. Their documentation states that I need to use an <code>async</code> function to connect.</p>
  <p>When I do that, the code gets 'stuck'. If I remove the <code>async</code> and <code>await</code> statement form the code below, it works. It would be ok to use it like that, but that's not a good pratice. Code fore ready.js follows:</p>
  <pre><code>const mongoose = require('mongoose')
  require('dotenv').config()
  const testSchema = require('../test-schema')
  
  module.exports = {
      name: 'ready',
      once: true,
  
  
  
      async execute(client, commands) {
          console.log(`Ready! Logged in as ${client.user.tag}`);
  
          await mongoose.connect(process.env.MONGO_URI);
          console.log(&quot;Database Connected!&quot;);
  
      },
  };
  </code></pre>
  <p>So, is it ok to just remove the async and await?</p>
  <p>Thanks in advance.</p>
  <p>Disclaimer: English is not my first language, sorry if it sounds confuse.</p>