discordjs / voice

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

Optional Client parameter for joinVoiceChannel() #206

Closed YetAnotherConnor closed 2 years ago

YetAnotherConnor commented 2 years ago

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

Describe alternatives you've considered

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 commented 2 years ago

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 commented 2 years ago

Yep, the answer given here is correct!