Delete audio resource
I have a simple system where an audio file is created, and then immediately turned into an audio resource. But it seems like creating an audioResource locks the file. How can I close the file handle to change the file? I obviously don't want to accumulate old unused files.
8 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!Even if the resource is never played by an audio player the file remains locked. Removing the reference variable does nothing. I have tried things like resource.destroy() or resource.playStream.destroy() but looking in the docs I don't see any function to just delete it and close the file handle. Once I call createAudioResource I can't delete the file without stopping the entire app.
if you're immediately playing then deleting the file, what is the purpose of creating a file in the first place?
is there a reason you're not just playing what I assume is a
ReadableStream
directly?because I've only played from files before and this was meant to be a quick thrown together thing
if this is just a fully wrong way to do this then I can do my own research to get it working directly with the streams, but if there is a way to just purge the resource and delete the file that would be easiest.
afaik destroying the resource should be what you're looking for, but you can just sidestep the issue with
createAudioResource(stream)
I can't find anything in the docs for destroying it tho
and my goofing around has yielded no results
sorry to be more specific, destroying the resource's stream should have been what you're looking for
but this really does seem like something to sidestep by skipping the file in the first place
fair enough