discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Music ends abruptly without log #3314

Closed JMTK closed 4 years ago

JMTK commented 5 years ago

I checked this before opening this. It seems to be the similar, but the dispatcher doesn't seem to fire any more events.

Please describe the problem you are having in as much detail as possible: This code has remained largely unchanged, but I used to be on https://github.com/discordjs/discord.js/commit/132788937a61490b5003117006f9e28164c14608 when it was first checked in and did not get latest src for a while. Once I got the current build(hash below), I had a couple of code updates to do with changing voiceConnection -> voice.connection etc. However some songs abruptly stop without error/debug log. A video it happened to was https://www.youtube.com/watch?v=penvn9VL32Y. However I restarted the bot and queued it again and it finished without stopping so it isn't consistent from my testing.

If I call my skip command to go to the next song in queue, it begins playing the next song as if nothing was wrong.

Include a reproducible code sample here, if possible:

//in another file
mybot.on('debug', (e) => {
    var err = e.toString().toLowerCase();
    if (err.includes("voice")) util.log("DEBUG>", e);
});

//in music file
let ytstream = ytdl(nextSong.url, {
  filter: "audioonly",
  quality: "highestaudio"
});

ytstream.on("error", err => {
  util.log("ytdl err: ", err.toString().split("\n")[0]);

  ytstream.destroy();

  musicReply(message, "There was an issue playing this track");
  moveToNextSongInQueue();
});

ytstream.on("info", async o => {
  let ts =
    nextSong.timestamp && !isNaN(nextSong.timestamp) ? nextSong.timestamp : 0;
  let volume = Config.AudioVolume;
  try {
    let l = o.loudness; //yt volume equalization
    volume = Number(((60 + (l && l < 0 ? l : -40)) / 100).toFixed(2));
  } catch (ex) {
    volume = Config.AudioVolume;
  }
  if (isNaN(volume)) {
    volume = Config.AudioVolume;
  }
  util.log("Intent Info", ts, volume); //this is usually something like 0, 0.2
  let intent = vCon.play(ytstream, {
    seek: ts,
    volume: volume
  });

  intent.on("debug", util.log);

  intent.once("error", e => {
    try {
      util.log("ERROR> Playing YouTube", e);

      if (e.toString().includes("ERR_STREAM_DESTROYED")) return;
      musicReply(message, "There was an issue playing this song.");
    } catch (ex) {
      util.log(ex);
    }
  });

  intent.once("finish", () => {
    try {
      ytstream.destroy();

      queue.splice(0, 1);
      playNextSong();
    } catch (ex) {
      util.log(ex);
    }
  });
});

Log output image

Further details:

The only optional package I have is zlib-sync.

I'm happy to provide more code/versions if needed.

hickleydonate commented 5 years ago

Try to remove all ffmpeg modules/packages, and use command npm i ffmpeg ALL FFMPEG MODULES/PACKAGES!!! Its work for me

JMTK commented 4 years ago

This seems mostly resolved by upping the highWaterMark value. I don't know if that's considered an acceptable solution though.

https://github.com/fent/node-ytdl-core/issues/402

iCrawl commented 4 years ago

3362