nodejs / help

:sparkles: Need help with Node.js? File an Issue here. :rocket:
1.46k stars 279 forks source link

Issue with ytdl-core / miniget #2513

Closed MrZBou closed 4 years ago

MrZBou commented 4 years ago

NPM@6.14.1 Windows 10 Issue with code

I am developing my own music (and not music only) bot for discord, I had a lot of problems with this, but I got a new one when I decided to turn the line of songs. An error started to appear in the console:

events.js:288
      throw er; // Unhandled 'error' event
      ^

Error: Status code: 416
    at ClientRequest.<anonymous> (C:\MrZBou Pack\HetcherBot\node_modules\miniget\dist\index.js:128:27)
    at Object.onceWrapper (events.js:418:26)
    at ClientRequest.emit (events.js:311:20)
    at HTTPParser.parserOnIncomingClient [as onIncoming] (_http_client.js:603:27)
    at HTTPParser.parserOnHeadersComplete (_http_common.js:119:17)
    at TLSSocket.socketOnData (_http_client.js:476:22)
    at TLSSocket.emit (events.js:311:20)
    at addChunk (_stream_readable.js:294:12)
    at readableAddChunk (_stream_readable.js:275:11)
    at TLSSocket.Readable.push (_stream_readable.js:209:10)
Emitted 'error' event on PassThrough instance at:
    at PassThrough.<anonymous> (C:\MrZBou Pack\HetcherBot\node_modules\ytdl-core-discord\node_modules\ytdl-core\lib\index.js:133:14)
    at PassThrough.emit (events.js:311:20)
    at ClientRequest.<anonymous> (C:\MrZBou Pack\HetcherBot\node_modules\miniget\dist\index.js:133:28)
    at Object.onceWrapper (events.js:418:26)
    [... lines matching original stack trace ...]
    at addChunk (_stream_readable.js:294:12)

Music commands:

async function play(connection, message, voiceChannel, song) {
  printt("Loading song: " + songQueue[0].title)
  if (isPlaying == false) {
      isPlaying = true
  }
  const dispatcher = connection.play(await ytdl(song.url), { type: 'opus', quality: [240], highWaterMark: 1<<20}, {highWaterMark: 1024 * 1024 * 1024})
 .on('finish', () => {
    message.channel.messages.fetch({ limit: 1 }).then(messages => {
    const lastMessage = messages.first()
    if (lastMessage.content == "") {
        lastMessage.delete()
    }
      }).catch(err => {
        console.error(err)
      })
        console.log('Music ended!' + songQueue[0].title)
          if (repeating == true) {
            startMusic(message, song, voiceChannel)
          }
          else {
              songQueue.shift()
              queueMsg(message)
              if (songQueue[0] != null) {
                  startMusic(message, songQueue[0], voiceChannel)
              }
              else {
                  isPlaying = false
              }
          }
 });
};

async function startMusic(message, song, voiceChannel) {
                  const videoEmbed = new MessageEmbed()
                 .setThumbnail(song.thumbnail) // song thumbnail
                 .setColor('#31caf9')
                 .addField('Сейчас играет:', song.title)
                 .addField('Длительность:', song.duration);
                 message.say(videoEmbed)
                voiceChannel.join()
                .then (connection => {
                    play(connection, message, voiceChannel, song);
                });
}

async function getTitle(message, memberVoiceChannel, getID) {
            message.channel.send("Загружаю..")
        .then(msg => {
            msg.delete({timeout: 1000})
          })
        if (!getID) {
    const videos = await youtube.searchVideos(message.content, 3)
    .catch(function() {
            printt("YouTube stop")
            return
        })
      try {
        var video = await youtube.getVideoByID(videos[0].id);
      } catch (err) {
        console.error(err);
        songEmbed.delete();
        return message.say(
          'Error with message'
        );
      }
      }
      else {

        var video = await youtube.getVideoByID(getID);
      }  
      const url = `https://www.youtube.com/watch?v=${video.raw.id}`;
      const title = video.title;
      secs = video.duration.seconds.toString()
      if (video.duration.seconds < 10) {   
          secs = (video.duration.seconds.toString() + "0")
      }
      if (video.duration.minutes < 10) {   
        var duration = ("0" + video.duration.minutes.toString() + ":" + secs)
      }
     else { 
        var duration = (video.duration.minutes.toString() + ":" + secs)
      }
      var realDuration = (video.duration.minutes * 60) + (video.duration.seconds)
      printt(duration)
      const thumbnail = video.thumbnails.high.url;
        if (duration == '00:00') duration = 'Live Stream';
        const song = {
          url,
          title,
          duration,
          thumbnail,
          voiceChannel,
          realDuration
        };
        songQueue.push(song)
        queueMsg(message)
        printt("Song Queue now: " + songQueue)
        if (memberVoiceChannel.joinable && !songQueue[1]) {
            voiceChannel = memberVoiceChannel
            startMusic(message, songQueue[0], voiceChannel)
    }
}
MrZBou commented 4 years ago

changed {highWaterMark: 1024 1024 1024} to {highWaterMark: 1024 1024 10} and the error disappeared

BoilingT commented 4 years ago

Thaaaaaaaaaaank youuuuuuuuuuuuuuuuuuuuuu!!!!!!!!!!!