Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question]: How to gracefully disconnect from a voice channel #13

Open
nullpat opened this issue Nov 14, 2024 · 8 comments
Open

[Question]: How to gracefully disconnect from a voice channel #13

nullpat opened this issue Nov 14, 2024 · 8 comments
Labels
bug Something isn't working not confirmed This issue or pull request is not confirmed to be done.

Comments

@nullpat
Copy link

nullpat commented Nov 14, 2024

FastLink version

2.4.1-rc.1

Description

player.destroy();

this leaves the bot connected to a voice channel

  const payload = {
    op: 4,
    d: {
      guild_id: guildId,
      channel_id: null,
      self_mute: false,
      self_deaf: false,
    },
  };
  client.guilds.cache.get(guildId).shard.send(payload);

setting channel_id here to null successfully disconnects the bot from the voice channel, however the bot has a 50% chance of blowing up with Uncaught TypeError TypeError: Cannot read properties of undefined (reading 'queue') at update (\node_modules\@performanc\fastlink\index.js:248:29) when trying to add a song to the queue after creating and connecting the player again. Feels like there is a race condition somewhere

  1. player.destroy();
  2. send disconnectPayload (channel_id set to null)
  3. player.createPlayer();
  4. player.connect
  5. add something to queue (sometimes blows up here on first pass, sometimes i repeat 1-5 again then it blows up)

How would you recommend disconnecting the bot from a voice channel? I'm not sure if im missing something obvious

Thank you for your time.

@nullpat nullpat added bug Something isn't working not confirmed This issue or pull request is not confirmed to be done. labels Nov 14, 2024
@nullpat
Copy link
Author

nullpat commented Nov 14, 2024

additionally FastLink.player.getPlayers does not work with lavalink

{timestamp: 1731625192214, status: 404, error: 'Not Found', message: 'No endpoint GET /v4/sessions.', path: '/v4/sessions'}

updating the getPlayers endpoint to /v4/sessions/${Nodes[node].sessionId}/players works

@ThePedroo
Copy link
Member

Are you sure you are calling .createPlayer() after .destroy() and .update() after .createPlayer()?

@nullpat
Copy link
Author

nullpat commented Nov 15, 2024

Yes, the easiest way for you to reproduce will be to add the following command to your example bot script

  if (commandName === "disconnect") {
    const payload = {
      op: 4,
      d: {
        guild_id: message.guild.id,
        channel_id: null,
        self_mute: false,
        self_deaf: false,
      },
    };
    client.guilds.cache.get(message.guild.id).shard.send(payload);
    message.channel.send("Disconnected.");
    return;
  }
  1. !play 123
  2. !stop
  3. !disconnect
  4. !play 123

Thanks again

@ThePedroo
Copy link
Member

You should se .connect(null, ...) instead also.

@nullpat
Copy link
Author

nullpat commented Nov 15, 2024

At present it doesn't allow null

  connect(voiceId, options, sendPayload) {  
    if (!voiceId) throw new Error('No voiceId provided.')

@ThePedroo
Copy link
Member

@nullpat
Copy link
Author

nullpat commented Nov 15, 2024

looks like npm is serving an old version
npm i @performanc/fastlink

    "dependencies": {
        "@performanc/fastlink": "^2.4.1-rc.1",```

@ThePedroo
Copy link
Member

I'll update it soon. I recommend to use GH version for now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working not confirmed This issue or pull request is not confirmed to be done.
Projects
None yet
Development

No branches or pull requests

2 participants