#Is it possible to fetch a subscribed AudioPlayer from a VoiceConnection?

11 messages · Page 1 of 1 (latest)

blazing spear
#

Hello there. So I'm making a song bot that plays local files. The current play command simply joins a voice channel (or moves to the current channel) and plays the song that was requested (from a selection of MP3 files on my local system). I am planning on making a queue system so you can queue whatever song you want. My problem comes with fetching the AudioPlayer. The discord.js/voice guide advised against keeping track of connections as you can accidentally create memory leaks. That said, I decided that I won't be keeping track of anything (apart from what is in the queue). From my understanding, an AudioPlayer is something like Media Player on Windows, an instance which a bunch of AudioResources can be passed in and it plays the latest one. If that is correct, then that means that it would be odd and wasteful to create an AudioPlayer for every single AudioResource, it would be the equivalent of opening a new Media Player window for every song. That being said, I plan on utilizing a single AudioPlayer per server. Now, since it was advised against to keep track of connections and such, is there a way for me to fetch that AudioPlayer using a VoiceConnection, or would I need to manually keep track of it? Also, would it maybe be better to create a new AudioPlayer for each song and just find a way to unsubscribe from the previous one? What do you recommend I do?

drifting sphinxBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
vale lake
#

<VoiceConnection>.state.subscription.player and keep one player per connection

#

Or even less, as multiple connections can subscribe to the same player if you want

blazing spear
#

Did they just forget to include it in the docs and in TS map?

vale lake
#

For it to show in ts you‘d need to typeguard it to have status ready first

#

And it shows on the docs, but as /voice is a ts library you should look at the new docs for that

blazing spear
#

Oh I see.

#

Thank you!