twlite / discord-ytdl-core

Simple ytdl wrapper for discord bots with custom ffmpeg args support.
https://www.npmjs.com/package/discord-ytdl-core
Apache License 2.0
51 stars 10 forks source link

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed #18

Closed Ebernn closed 3 years ago

Ebernn commented 3 years ago

Hi, I just want to run

const ytdl = require('discord-ytdl-core');
...
const dispatcher = serverQueue.connection
    .play(ytdl(song.url, {
      filter: 'audioonly',
      opusEncoded: true,
      encoderArgs: ['-af', queue.filters],
    }))
...

but it throws

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

Error [ERR_STREAM_DESTROYED]: Cannot call write after a stream was destroyed
    at doWrite (_stream_writable.js:399:19)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at PassThrough.ondata (_stream_readable.js:716:22)
    at PassThrough.emit (events.js:315:20)
    at addChunk (_stream_readable.js:295:12)
    at readableAddChunk (_stream_readable.js:271:9)
    at PassThrough.Readable.push (_stream_readable.js:212:10)
    at PassThrough.Transform.push (_stream_transform.js:152:32)
    at PassThrough.afterTransform (_stream_transform.js:96:10)
Emitted 'error' event on FFmpeg instance at:
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at FFmpeg.onerror (_stream_readable.js:752:7)
    at FFmpeg.emit (events.js:315:20)
    at Socket.processError (F:\projects\discord\bot\musicbot\node_modules\prism-media\src\core\FFmpeg.js:64:40)
    at Socket.emit (events.js:315:20)
    at errorOrDestroy (internal/streams/destroy.js:108:12)
    at onwriteError (_stream_writable.js:418:5)
    at onwrite (_stream_writable.js:445:5)
    at doWrite (_stream_writable.js:399:11)
    at writeOrBuffer (_stream_writable.js:387:5) {
  code: 'ERR_STREAM_DESTROYED'
}

Version

Windows 10 64 bits
ffmpeg v3.4
node v12.18.4
"@discordjs/opus": "^0.3.3",
"discord-ytdl-core": "^5.0.0",
"discord.js": "^12.4.1",

Tests

tested song tested mix (same error)

Thank you in advance

twlite commented 3 years ago

try using connection.play(ytdl(...), { type: "opus" })

Ebernn commented 3 years ago

Doesn't solve the issue, the same error is thrown. I just noticed that without encoderArgs option, the stream just finishes prematurely without throwing any error (and no sound is heard).

twlite commented 3 years ago

Are you using

const dispatcher = serverQueue.connection
    .play(ytdl(song.url, {
      filter: 'audioonly',
      opusEncoded: true,
      encoderArgs: ['-af', queue.filters],
    }), { type: 'opus' })

right now?

twlite commented 3 years ago

And just now tested your songs and they are doing good. Btw, what's queue.filters? Looks like your queue.filters is wrong?

Ebernn commented 3 years ago

HAHA! Thanks! šŸ”„

The culprits are my cursed eyes, I wrote

const dispatcher = serverQueue.connection
    .play(ytdl(song.url, {
      filter: 'audioonly',
      opusEncoded: true,
      encoderArgs: ['-af', queue.filters],
    }, { type: 'opus' }))

instead of

const dispatcher = serverQueue.connection
    .play(ytdl(song.url, {
      filter: 'audioonly',
      opusEncoded: true,
      encoderArgs: ['-af', queue.filters],
    }), { type: 'opus' })