Getting existing audio player

how do i get the audio player in a guild if any?
23 Replies
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Kinect3000
Kinect30003y ago
Audio players are not specific to guilds, you can have many connections (across several guilds) subscribed to the same player
Shaurya
ShauryaOP3y 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
Kinect30003y ago
Why would you need a handler for player events?
Shaurya
ShauryaOP3y 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
Kinect30003y ago
I just register the events the normal way after creating the player Are you registering 20 events per player or smth?
Shaurya
ShauryaOP3y ago
wdym? thunk
Kinect3000
Kinect30003y ago
player.on("idle", …).on("error", …)
Shaurya
ShauryaOP3y ago
can i like create the player initially and export it and can use it?
Kinect3000
Kinect30003y ago
Why would you do that? You want the same thing to play in every guild?
Shaurya
ShauryaOP3y ago
no no lol
Kinect3000
Kinect30003y ago
Then no, you can’t do that
Shaurya
ShauryaOP3y 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
Kinect30003y ago
Either store it separately or use connection.state.player connection is obtainable by getVoiceConnection(guildId)
Shaurya
ShauryaOP3y ago
oh that returns the player?
Kinect3000
Kinect30003y ago
Assuming the connection is subscribed to the player
Shaurya
ShauryaOP3y ago
hmm got it, i subscribe the player like this:
connection.subscribe(player);
connection.subscribe(player);
it's ok right
Kinect3000
Kinect30003y ago
Yea Oop, forgot .subscription connection.state.subscription.player
Shaurya
ShauryaOP3y ago
oh ._.
Kinect3000
Kinect30003y ago
Yea, not rly a big fan of it tbh
Shaurya
ShauryaOP3y ago
hmm
Kinect3000
Kinect30003y ago
mmh
Shaurya
ShauryaOP3y ago
hey btw, what event should i use for getting the guild id
Want results from more Discord servers?
Add your server