shipgirlproject / Shoukaku

A stable, powerful and updated wrapper around Lavalink
https://guide.shoukaku.shipgirl.moe/
MIT License
287 stars 86 forks source link

"PlayerStart" and "playerEnd" event on the client #38

Closed sawa-ko closed 3 years ago

sawa-ko commented 3 years ago

It would be nice to have an event in the client called playerStart and playerEnd, and to be executed every time a guild player starts or ended.

I say this idea in order to better manage the control of players from one place.

Example:

const client = new Shoukaku(options);
client.on("playerStart", (guildId, player) => console.log(guildId, player));

client.on("playerEnd", (guildId, player) => console.log(guildId, player));
Deivu commented 3 years ago

What kind of management

sawa-ko commented 3 years ago

For example:

  1. Better queue control to not rely on the .getPlayer() method and avoid having many active listeners in different commands.
  2. Send notification messages in a simpler way when the music player stops or starts.
  3. The most important thing is to be able to do everything from one place and not from several commands.
Deivu commented 3 years ago

Possible to be considered on next but definitely will not ship in current v1, though I'm not sure how you are not being able to do everything in one place, are you not extending, or making a queue system around the player?

sawa-ko commented 3 years ago

When I say in one place I mean to manage a queue system for example from a service class, and not to depend on any command.

Sometimes I get an error that says Shoukaku reached max listeners and things like that, that's why I give that idea. That happens by having listeners in commands.

Deivu commented 3 years ago

When I say in one place I mean to manage a queue system for example from a service class, and not to depend on any command.

Sometimes I get an error that says Shoukaku reached max listeners and things like that, that's why I give that idea. That happens by having listeners in commands.

I usually just store shoukaku player as a property on my own player, then attach listeners on the constructor or have a specific init method that would only be executed once, so you wont re-add any listeners once added

sawa-ko commented 3 years ago

Do you have any examples of how to implement that in that way you mention?

But also, it would be nice if those listeners were available in the client, I hope that in the future you can put it.

Deivu commented 3 years ago

// create a play function that accepts an existing player
async play(player) {
  const song = await player.voiceConnection.node.resolve('something');
  await player.playTrack(song);
}
// create a player variable, where in we will attach listeners on it once only
const player = await node.joinVoiceChannel();
// use the play function to play your queue, instead of attaching listeners per play function
player.on('end', () => play(player));
// execute play for the first time
play();
sawa-ko commented 3 years ago

Yes I do, but there are times when I get the error I mentioned even when using a method like that.

Deivu commented 3 years ago

Yes I do, but there are times when I get the error I mentioned even when using a method like that.

Are you sure you are not re attaching listeners? the ideal scenario is to ensure you only attach the listeners at once

sawa-ko commented 3 years ago

Yes, I make sure of that but sometimes I get that error, that's why I suggested this issue

Deivu commented 3 years ago

I can consider this, but definitely will not ship in current 1.6.x, if considered, expect this to be on 2.x.x, and most likely is not a Shoukaku issue, because as far as I know, me, and other users that use this lib don't encounter this particular issue

sawa-ko commented 3 years ago

Okay, thanks for adding this feature in the future that may be useful for others as well

Deivu commented 3 years ago

Check latest next-branch commits, new events on Shoukaku Class have been added, named playerReady and playerDestroy