Error: Cannot play a resource that has already ended.
Hey, i have thsi error when im trying to play a radio flux url like (for example) http://belrtl.ice.infomaniak.ch/belrtl-mp3-192.mp3
This is my code:
31 Replies
- What's your exact discord.js
npm list discord.js
and node node -v
version?
- Not a discord.js issue? Check out #other-js-ts.
- Consider reading #how-to-get-help to improve your question!
- Explain what exactly your issue is.
- Post the full error stack trace, not just the top part!
- Show your code!
- Issue solved? Press the button!
- ✅
Marked as resolved by staffPlz @ me
discord js v14 with node 16.20
"discord.js": "^14.9.0",
"@discordjs/opus": "^0.9.0",
"@discordjs/voice": "^0.16.1",
Where's the full error + backtrace?
hi, can someone fix it ?
throw new Error("Cannot play a resource that has already ended.");
^
Error: Cannot play a resource that has already ended.
Uh, the error explains itself
but radio link is working, and bot was working with this link
You shall not re-use a stream
so how to destroy it ?
You mean how to re-create it?
ye, can i show you my code in dms ?
it will be easier for you & me
Well, I don't need the code, so..
ye but i think i do what u are saying
You can simply call the .createAudioResource function again and use it
I need the full backtrace
But the overlap of variable names can be problematic
wdym ? the eror ? (srry im french)
with this code its logging console.log('Audio player is idle. Restarting playback.'); to infinity
Let me find my old code to give as example
1s
👍
GitHub
NodeLink/src/connection/voiceHandler.js at v1.14.1 · PerformanC/Nod...
Performant LavaLink alternative written with Node.Js - PerformanC/NodeLink
This line is what you want to use it to check if the stream really ended
The rest of the code may have some other codes you may find useful to improve yours
But in any way, I'd name the resource variable names another name inside the .on
As they have the same name as the one above them
The
At xxx
messagesWhat's the line 36 in your play.js file?
player.play(currentResource);
Which one of them?
Also
Is track an URL or stream?
on the assumption this is the one that plays when the connection becomes ready, it doesn't look like you have any cleanup for this event listener
connections are reused if not destroyed when connecting to a channel in the same guild, so if this code executes a second time for the same guild, this ready listener will execute a second time attempting to play the same resource
furthermore a connection can in general become ready more than once on its own depending on a number of factors (e.g. if it disconnects due to poor network and reconnects)
Also, avoid re-using the same variable -- instead of checking if the stream is null, just do the other if to check when the stream "ends"
But my code works on my computer and was working on my vps, but after 3 month 💤
Sometimes you only find bugs later on
Discord voice didn't change since then, neither djs/voice unless you changed the version
So it's a bug that has been already there since there, but you've never found out
Take advantage of this and improve the code to be more robust (.e.g* proper checks and more robust design)
I wasn't going to relaunch this bot because the code is too old... I'll see if I can do it again... if not, too bad!
Well, we're here to help. I recommend to first fix the main issue (duck said a possible issue, which even if it's not the issue here, it should be patched) then later on focus on make it more robust
:Check: , thanks guys