title: Why am I unable to catch discord.js promise rejections in event callbacks?
body: <p>So I'm making a discord bot. For simplicity's sake, here is a <em>very</em> small portion that illustrates my problem:</p>
  
  <pre><code>const Discord = require('discord.js');
  
  const client = new Discord.Client();
  
  client.on('ready', async () =&gt; {
    throw new Error('Omg');
  });
  
  async function start() {
    try {
      await client.login(process.env.DISCORD_BOT_TOKEN);
    } catch (err) {
      console.error('Caught the promise rejections');
    }
  }
  
  start();
  </code></pre>
  
  <p>When I run this code, I expect the output to be <code>Caught the promise rejections</code> and the process should subsequently exit. However this is not the case. Instead I get a <code>PromiseRejectionWarning</code> and the process does not exit (I have to press Ctrl-C to do so). I first thought that maybe errors in callbacks don't get propagated to code that calls them, so I made another pure JS example:</p>
  
  <pre><code>const client = {
    on(event, callback) {
      this.callback = callback;
    },
  
    async login(token) {
      while (true) {
        // I assume the login method calls the callback in D.js 
        // (where else could it be called?)
        await this.callback();
        await sleep(5000);
      }
    },
  };
  
  client.on('ready', async () =&gt; {
    throw new Error('Omg');
  });
  
  async function start() {
    try {
      await client.login(process.env.DISCORD_BOT_TOKEN);
    } catch (err) {
      console.error('Caught the promise rejections');
    }
  }
  
  start();
  </code></pre>
  
  <p>However in this case, the output is exactly as expected; I see the line from the catch and the process immediately exits. Without the catch I get the unhandled promise rejection errors and an unfinished process.</p>
  
  <p>So my question: Why am I unable to catch promise rejections in my event callbacks (like <code>on('ready')</code>)?</p>