title: Playing an audio file using discord.js and ytdl-core
body: <p>I'm trying to download and play an audio file fetched from youtube using ytdl and discord.js:</p>
  
  <pre><code>        ytdl(url)
              .pipe(fs.createWriteStream('./music/downloads/music.mp3'));
  
          var voiceChannel = message.member.voiceChannel;
          voiceChannel.join().then(connection =&gt; {
              console.log("joined channel");
              const dispatcher = connection.playFile('./music/downloads/music.mp3');
              dispatcher.on("end", end =&gt; {
                  console.log("left channel");
                  voiceChannel.leave();
              });
          }).catch(err =&gt; console.log(err));
          isReady = true
  </code></pre>
  
  <p>I successfully manage to play the mp3 file in ./music/downloads/ without the ytdl part (<code>ytdl(url).pipe(fs.createWriteStream('./music/downloads/music.mp3'));</code>). But when that part is in the code, the bot just joins and leaves.</p>
  
  <p>Here is the output with the ytdl part:</p>
  
  <pre><code>Bot has started, with 107 users, in 43 channels of 3 guilds.
  joined channel
  left channel
  </code></pre>
  
  <p>And here is the output without the ytdl part:</p>
  
  <pre><code>Bot has started, with 107 users, in 43 channels of 3 guilds.
  joined channel
  [plays mp3 file]
  left channel
  </code></pre>
  
  <p>Why is that and how can i solve it?</p>