discordjs / voice

Implementation of the Discord Voice API for discord.js and other JS/TS libraries
Apache License 2.0
327 stars 111 forks source link

Player and Connection getter's functions are not working. #180

Closed bymayfe closed 3 years ago

bymayfe commented 3 years ago

Please describe the problem you are having in as much detail as possible: new AudioPlayer()'s functions and getVoiceConnection()'s functions are not working. But joinVoiceChannel()'s and createAudioPlayer()'s functions are working.

Include a reproducible code sample here, if possible: new AudioPlayer().stop() and getVoiceConnection(message.guild.id).subscribe(player)

  var player = new AudioPlayer(message.guild.id);
  player.stop();
  player.pause(); 
  player.unpause()

  /*-------------OTHER FUNCTION----------------*/
  var connection = getVoiceConnection(message.guild.id);
  connection.subscribe(player);

  // Dont same function 
  var connection = getVoiceConnection(message.guild.id);
  var connection = joinVoiceChannel()

  //and
   var player = new AudioPlayer();
   var player = createAudioPlayer()

Further details:

Relevant client options:

iim-ayush commented 3 years ago

First of all, there is no function like connection.subscripte(player);

Secondly, you don't need to create AudioPlayer in that manner :

Refer to this for creating AudioPlayer

You don't need to pass a guild id in AudioPlayer like that.

Moreover, voice connection .subscribe is only a function when a connection is in ready state.

The last image is also true as connection.subscribe() returns a PlayerSubscription not a connection.

First Read DOCS completely and then create a issue

bymayfe commented 3 years ago

I already read DOCS completely and ı know create player. My question are => Are there player and connection I created and a function that the connection from somewhere else and use ? connection.subscribe(player); function => sorry for the spelling mistake

iim-ayush commented 3 years ago

I already read DOCS completely and ı know create player. My question are => Are there player and connection I created and a function that the connection from somewhere else and use ? connection.subscribe(player); function => sorry for the spelling mistake

Probably your codes are somewhere confusing you and forcing you to create this issue.

First start with basic examples as in guide and then start making classes.

bymayfe commented 3 years ago

ı know ı make already system but The main thing I was wondering was how I could use it with getter functions. When I tried, I couldn't get the system to work with the getter functions.

iim-ayush commented 3 years ago

ı know ı make already system but The main thing I was wondering was how I could use it with getter functions. When I tried, I couldn't get the system to work with the getter functions.

Leave everything aside, tell me how can you pause a player which is in idle state ??? As clearly seen in your images

image

bymayfe commented 3 years ago

Ist just example. Try getter functins stop pause and unpause and reply please.

getVoiceConnection(message.guild.id) || new AudioPlayer()
iim-ayush commented 3 years ago

Ist just example. Try getter functins stop pause and unpause and reply please.

getVoiceConnection(message.guild.id) || new AudioPlayer()

Ok taking your same example. First of all, AudioPlayer takes options not guild ID. So leaving that aside, now let's talk about stop and pause and unpause functions.

Suppose You have a music player ( for e.g. Groove Music ) and you open it. It will be in idle state since player has nothing to load.

Once you click a music file, its state changes from idle to playing and also controls come up. Then in playing state only, you can pause, unpause and stop functions will work. as see by your images all those functions are working great you just need to play a resource.

bymayfe commented 3 years ago

Okey. Let me try to explain it like this. -- https://youtu.be/-CdaH4l5Cd8

if ı set player and connection new Map(); ı can get and use pause unpause and stop function.

and maybe getVoicePlayer function must be added

iim-ayush commented 3 years ago

Okey. Let me try to explain it like this. -- https://youtu.be/-CdaH4l5Cd8

if ı set player and connection new Map(); ı can get and use pause unpause and stop function.

and maybe getVoicePlayer function must be added

Thanks for the video, I fully understand your problem now.

You can create your own getter function named getVoicePlayer() by this code :

const { getVoiceConnection } = require('@discordjs/voice');

function getVoicePlayer(guild_id){
    let connection = getVoiceConnection(guild_id);
    if(!connection) return undefined
    if(connection.state?.subscription?.player) return connection.state.subscription.player
    else return undefined
}
bymayfe commented 3 years ago

Thank you so much for the explanation. So how can i make a subscription with getVoiceConnection() function. can i do it is it possible

bymayfe commented 3 years ago

Okey ı find this function thanks for interest <3

iim-ayush commented 3 years ago

No Problem 👍