node-ytdl-core: Error: imput stream: aborted
Today i wrote simple play command for discord bot. But after some time of music plaing i get this error My code for music play is:
const { Permissions:{FLAGS} } = require ("discord.js")
const ytdl = require('ytdl-core')
const fs = require('fs')
module.exports={
name: "play",
description: "Puszczanie muzyki",
args: true,
usage: "<tytuł/url>",
guildOnly: true,
cooldown: 10,
aliases: ["p"],
botPermissions: [FLAGS.CONNECT,FLAGS.SPEAK],
async run(message, args) {
//console.log(args)
const voiceChannel = message.member.voice.channel
if(!voiceChannel) return message.channel.send("Potrzebujesz być na kanale głosowym by to zrobić")
try {
var connection = await voiceChannel.join()
} catch (error) {
console.log(`There was an error connecting to the voice channel: ${error}`)
}
const dispatcher = connection.play(ytdl(args[0],{Quality: 'highestaudio'},{filter:'audiooly'},{highWaterMark: 1<<23},{dlChunkSize:0}))
.on('finish',() => {
voiceChannel.leave()
})
.on('error', error => {
console.log(error)
})
dispatcher.setVolumeLogarithmic(5 / 5)
}
}
Any ideas how to fix it ?
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 5
- Comments: 65 (16 by maintainers)
Commits related to this issue
- feat: add queue Added queue and also replaced ytdl-core with play-dl due to crashing issues see https://github.com/fent/node-ytdl-core/issues/902 — committed to macluxHD/aqua by macluxHD 2 years ago
- The solution provided by 0xAnakin in https://github.com/fent/node-ytdl-core/issues/902 seems to fix Issue #1 . Not tested extensively though. — committed to CombustibleToast/CAROLINE by CombustibleToast a year ago
- seek改短試試,ytdl-core highWaterMark 設定 32768(32KB) 可以避免中斷 https://github.com/fent/node-ytdl-core/issues/902 — committed to Mr-Smilin/AliceZero by deleted user 10 months ago
- fix: Error: aborted (increase highWatermark option to 32MiB) https://github.com/fent/node-ytdl-core/issues/902 — committed to Loupsito/discord-ely-bot by Loupsito 3 months ago
- fix: Error: aborted (increase highWatermark option to 32MiB) https://github.com/fent/node-ytdl-core/issues/902 — committed to Loupsito/discord-ely-bot by Loupsito 3 months ago
Using such settings from ytdl-core allows you playing songs over 60 mins with easy and no abortion error at all
Why bitrate 128?
Confirmed, setting ytdl-core highWatermark option to 32MiB on Node.js v16 (16.5.0) fixes the problem, so the workarounds are use Node v14.x or play with the highWatermark settings, not sure if this will apply to everyone
This solve my problem, unfortunately ytdl still broken given an issue with miniget
#EDIT
If you wanna replace ytdl as well have a look in the example bellow, here I replace my ytdl stream with play-dl stream
##Before:
##After:
Been getting this issue after playing for a while. then it errors out.
Node: 16.6.1 ytdl-core: 4.9.1
So im running a small discord bot called Tinker I run development on my laptop and production on my raspberry pi. The issue does not seem to occur when in development. The only differences are, of course the OS, and the nodejs version. The code is the exact same Here are the stats of the two:
Development (no issues) Windows Home (latest updates)
node index.js
run directly in terminal (Command Prompt) nodejs: v14.16.1Production (fairly regular “Input Stream Aborted” errors) Raspbian (latest updates)
pm2 start tinker
pm2 process manager, configured with the correct nodejs runtime nodejs: v16.0.0Edit
I have just done a further test, running my production with all the same settings and system but with nodejs v 14.16.1 and no errors whatsoever. Nodejs version appears to be the culprit (at least in my instance). I hope this helps some people with issues and the devs with fixing the error. Love the package and keep up the good work!
Still broken.
A substitute package: https://www.npmjs.com/package/play-dl
Recently I came up with idea with fragmental downloads. and everything works well for me by downloading tiny fragments that are each as small as 1MB and piping them into one stream. for example:
I hope this will help. P.S. the tricky solution that I wrote in this issue before doesn’t work well now in current version of discord.js. It will work in discord.js v13.1.0 only.
Still no valid solutions? 2024 and still this issue persists in discord/js bots. The one provided above by 0xAnakin doesn’t work.
I captured network traffic using Wireshark. I found that a remote server sends a “TCP [RST]” packet (to close the connection) after the node.js sends “TCP ZeroWindow” packets some times. Also I’ve noticed a “TCP Window Update” packet is successfully sent some times. However I couldn’t found any invalid network packet likely to cause connection reset. It looks like all working properly. (I might have overlooked because I’m a newbie of analyzing of network)
Anyway, if you want to use discord.js v13, I noticed you can provisionally use discord.js v13 with Node.js v14 or less. In order to run discord.js v13 on Node.js v14 or less, (a tricky way though) install
AbortController
npm package and write code below before calling the discord.js module. This makes discord.js work properly.Of course this solution might become unusable depending on updates since this is not a solution to the actual cause and right way to use discord.js v13. This works currently properly in my environment. sorry for my bad english
P.S. It will work in discord.js v13.1.0 only. In higher versions this won’t work well.
I am having tha same issue. I got a direct video url (like
https://r8--***.googlevideo.com/videoplayback?***
) viayoutube-dl
and tried playing directly with the url usingminiget
, but aborted error still occurred. Though this is not what prove the issue is of miniget, I think it might be the helpful information.highWaterMark
option won’t solve the actual cause of the issue because it only makes the time to the error an error occurs longer.node
: v16.6.1discord.js
: v13.1.0@discordjs/voice
: v0.6.0ytdl-core
: v4.9.1miniget
: v4.2.1Well if I could hug you I would, I had to force it to update to the latest version of discord/js (npm i @discordjs/voice@latest) and switched to the core you use and I’m in business again. Appreciate the quick response!
I just gave up of this package. Switched over @distubejs/ytdl-core. Working perfectly for this situation.
I love this solution 😄
OK lol.
I have this error show up quite frequently. I’ve run the ytdl-core tests by cloning the repo etc and no issues there The issue seems to arise after some time of playing, at which point it will crash and throw the error mentioned earlier.
I am running discord js 12.5.1 and ytdl-core 4.5.0 This has been occurring across multiple versions of ytdl-core for me.
Node: 15.5.1 Running on Ubuntu I can provide more info if needed