Incorrect client joins channel when using joinVoiceChannel()

discord.js@14.11.0 npm v18.16.0 I have multiple clients logged in and I am trying to connect specific ones to different voice channels. The first time I do this it works fine; the correct bot (Loudspeaker 4) joins the correct channel. The next time I try to do this with a different bot (Loudspeaker 3), Loudspeaker 4 joins the channel instead despite Loudspeaker 3 instantiating the guild and channel. Here's the relevant code:
//In another function, these calls are made
//get the client
const loudspeakerClient = loudspeakerList.get(loudspeakerAssignmentResult.loudspeakerId);
//get the channel object
const voiceChannel = await loudspeakerClient.channels.fetch(interaction.member.voice.channel.id);
initLoudspeaker(loudspeakerClient, voiceChannel);
//...

async function initLoudspeaker(loudspeakerClient, channel) {
//loudspeakerClient is a Client object, channel is a BaseChannel object of a voice channel

const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
console.log(`initializing "${loudspeakerClient.user.username}"`);
console.log(`Channel "${channel.name}" instantiated by "${channel.client.user.username}"`);
console.log(`Guild instantiated by "${channel.guild.client.user.username}"`);
loudspeakerClient.connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});

//function continues...
}
//In another function, these calls are made
//get the client
const loudspeakerClient = loudspeakerList.get(loudspeakerAssignmentResult.loudspeakerId);
//get the channel object
const voiceChannel = await loudspeakerClient.channels.fetch(interaction.member.voice.channel.id);
initLoudspeaker(loudspeakerClient, voiceChannel);
//...

async function initLoudspeaker(loudspeakerClient, channel) {
//loudspeakerClient is a Client object, channel is a BaseChannel object of a voice channel

const { joinVoiceChannel, createAudioPlayer, NoSubscriberBehavior } = require('@discordjs/voice');
console.log(`initializing "${loudspeakerClient.user.username}"`);
console.log(`Channel "${channel.name}" instantiated by "${channel.client.user.username}"`);
console.log(`Guild instantiated by "${channel.guild.client.user.username}"`);
loudspeakerClient.connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator
});

//function continues...
}
For the first connection, this is printed:
initializing "Loudspeaker 4"
Channel "General" instantiated by "Loudspeaker 4"
Guild instantiated by "Loudspeaker 4"
initializing "Loudspeaker 4"
Channel "General" instantiated by "Loudspeaker 4"
Guild instantiated by "Loudspeaker 4"
and the correct bot joins General as expected. When I move to a different channel and attempt the same thing, this is printed:
initializing "Loudspeaker 3"
Channel "Second Channel" instantiated by "Loudspeaker 3"
Guild instantiated by "Loudspeaker 3"
initializing "Loudspeaker 3"
Channel "Second Channel" instantiated by "Loudspeaker 3"
Guild instantiated by "Loudspeaker 3"
This should indicate that Loudspeaker 3 will join, but in reality Loudspeaker 4 just switches channels. According to this: ⁠https://discord.com/channels/222078108977594368/1090014703209693194/1090123144594980934, the guild.voiceAdapterCreator will cause the client who instantiated the guild to connect. As the logs show, L3 is instantiating the guild used to get the adapter. Additionally, Loudspeaker 4's connection updates to reflect the new channel, even though the connection is being assigned to Loudspeaker 3. This is shown by the log of the client, and the connection is assigned to that client. Any ideas on what's going wrong here?
4 Replies
d.js toolkit
d.js toolkit14mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
CombustibleToast
CombustibleToast14mo ago
discord.js@14.11.0 @discordjs/voice@0.16.0 npm v18.16.0 i see
CombustibleToast
CombustibleToast14mo ago
CombustibleToast
CombustibleToast14mo ago
do I have to use something specific or does it just need to be any unique string thanks Yeah that was the problem, thank you