Getting existing audio player

how do i get the audio player in a guild if any?
23 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30002y ago
Audio players are not specific to guilds, you can have many connections (across several guilds) subscribed to the same player
Shaurya
ShauryaOP2y ago
like i'm making a djs voice events handler but i create the player in the file where it is used, could i just do like
const djsvoice = require('@discordjs/voice');
const player = djsvoice.createAudioPlayer();
const djsvoice = require('@discordjs/voice');
const player = djsvoice.createAudioPlayer();
and it'll be good to go for handling the events?
Kinect3000
Kinect30002y ago
Why would you need a handler for player events?
Shaurya
ShauryaOP2y ago
like for the queue system when the player gets idle i check if there's any song in the queue and then play it
Kinect3000
Kinect30002y ago
I just register the events the normal way after creating the player Are you registering 20 events per player or smth?
Shaurya
ShauryaOP2y ago
wdym? thunk
Kinect3000
Kinect30002y ago
player.on("idle", …).on("error", …)
Shaurya
ShauryaOP2y ago
can i like create the player initially and export it and can use it?
Kinect3000
Kinect30002y ago
Why would you do that? You want the same thing to play in every guild?
Shaurya
ShauryaOP2y ago
no no lol
Kinect3000
Kinect30002y ago
Then no, you can’t do that
Shaurya
ShauryaOP2y ago
like i just need to use the events to do different things but like i create the player in the play.js file then how would i use the player in other files?
Kinect3000
Kinect30002y ago
Either store it separately or use connection.state.player connection is obtainable by getVoiceConnection(guildId)
Shaurya
ShauryaOP2y ago
oh that returns the player?
Kinect3000
Kinect30002y ago
Assuming the connection is subscribed to the player
Shaurya
ShauryaOP2y ago
hmm got it, i subscribe the player like this:
connection.subscribe(player);
connection.subscribe(player);
it's ok right
Kinect3000
Kinect30002y ago
Yea Oop, forgot .subscription connection.state.subscription.player
Shaurya
ShauryaOP2y ago
oh ._.
Kinect3000
Kinect30002y ago
Yea, not rly a big fan of it tbh
Shaurya
ShauryaOP2y ago
hmm
Kinect3000
Kinect30002y ago
mmh
Shaurya
ShauryaOP2y ago
hey btw, what event should i use for getting the guild id
Want results from more Discord servers?
Add your server