Skip to content
This repository has been archived by the owner on Jul 12, 2023. It is now read-only.

Optional Client parameter for joinVoiceChannel() #206

Closed
YetAnotherConnor opened this issue Sep 17, 2021 · 2 comments
Closed

Optional Client parameter for joinVoiceChannel() #206

YetAnotherConnor opened this issue Sep 17, 2021 · 2 comments

Comments

@YetAnotherConnor
Copy link

Is your feature request related to a problem? Please describe.
There does not appear to be any way to specify a Client when using joinVoiceChannel. For processes with more than one Client, it is uncontrollable which Client joins the voice channel. In my testing, a Client consistently joins with the same code ran; however a different Client could join instead after changing code, even seemingly unrelated code.

Describe the ideal solution

  • Allow an optional Client parameter:
const connection = joinVoiceChannel({ ...options }, client );

Describe alternatives you've considered

  • I have attempted to trace back from the initial joinVoiceChannel call to try and find how/where a client is found to no avail.
  • I tested extending Client with a method which calls joinVoiceChannel using the guild object from the client's own cache, which had the same behavior as above.
const { Client, Intents } = require('discord.js');
const { joinVoiceChannel } = require("@discordjs/voice");

module.exports = class TestBot extends Client {
  constructor(config) {
    super({
      intents: [Intents.FLAGS.GUILD_VOICE_STATES, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILDS],
    });
    this.config = config;
  }

  testBotJoinVoiceChannel(channelId, guildId) {
    const guild = this.guilds.cache.get(guildId);
    if (!guild) return null;
    let conn = joinVoiceChannel({
      guildId,
      channelId,
      adapterCreator: guild.voiceAdapterCreator,
    });
    return conn;
  }
};
  • I even tried using a different js library to control the bot connections, which worked! ...but since the connection objects between libraries are not compatible, it crashed soon after :(

Additional context
I am attempting to create a system of bots where one "controller" receives interaction events and multiple "player" bots that join voice channels playing music. Ideally this system would only require users to interact with the "controller," but as I am unable to control which client is joining it's a bit hard...
If someone who knows how/where a client is found when calling joinVoiceChannel I would love to know too!

@mattoz0
Copy link

mattoz0 commented Sep 22, 2021

I also had this question, however on further inspection i think this is how it works.

  1. You need to specify the group id (set as client id so it doesn't overwrite other connection).
  2. When you pass the adapterCreator pass it from the guild object, that is inside the client you want to connect.
      joinVoiceChannel({
        channelId: this.channel.id,
        guildId: this.channel.guild.id,
        group: this.channel.client.user.id,
        adapterCreator: this.channel.guild.voiceAdapterCreator
      });

Ill test this theory shortly!

@amishshah
Copy link
Member

Yep, the answer given here is correct!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants