Loading Files synchronously

Hello! I am currently making a slash command to load in a txt file and place the lines in an object and then manipulate the object. Everything in the code is running as expected. There is only just one problem - the execute function for the slash command does not wait for my file to close. The consequence of this is that the object is not ready to be manipulated when the next function is called, and thus crashes the application. I am using fs.readstream to read the file Here is the binpath to the slash command file: https://pastebin.com/wEwdrxLQ The crash is expected of the behavior described above. I get TypeError: Cannot read properties of undefined (reading '[random int]') From testing, what I believe is happening is that in getTracks, the function goes through once, returns undefined, and then goes onto the next function. The function does not stay in the readstream as long as the file is open. One solution would be to put all the post-processing functions inside the close event, but that would be rather clunky and tedious Another solution I tried was to make execute asynchronous and put await in front of the call to getTracks. This did not work. A final solution I tried was to put the read events in a while loop with a sentinel that would be changed on the close event. This only prevented from any events being able to be read. Thank you for reading this!
Pastebin
Export - Pastebin.com
Pastebin.com is the number one paste tool since 2002. Pastebin is a website where you can store text online for a set period of time.
4 Replies
d.js toolkit
d.js toolkit5w ago
- 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 staff
Gallion
GallionOP5w ago
Oh I forgot to tag this as node
treble/luna
treble/luna5w ago
this is more suited for #other-js-ts
Gallion
GallionOP5w ago
Ah that's fair
Want results from more Discord servers?
Add your server