(v13) Target not connected to voice

Our bot is not able to correctly move certain members. Even though they are connected to a channel the bot has acces to, it returns Error: Error moving user: DiscordAPIError: Target user is not connected to voice.

It runs v13 since it's hosted by our FiveM server. Which doesn't have the node Discord.js needs.

async function DiscordConnect(radioChan, identifier, source) {
  var dcIdentifier = identifier;
  var dcId = dcIdentifier.split(":")[1];
  var radioNum = radioChan.toString();
  const botServer = client.guilds.cache.get(guildid);
  const member = await botServer.members.fetch(dcId);

  const logChannel = client.channels.cache.get(logchannelid);

  // logChannel.send('Bot is online')
  const readyEmbed = new MessageEmbed()
    .setTitle(translation["connecting"])
    .setDescription(
      translation["player"] +
        `<@${dcId}>` +
        translation["trying-to-connect"] +
        ` ${radioNum}`
    )
    .setFooter(`Discord identifier: ${dcIdentifier}`)
    .setColor("YELLOW");
  logChannel.send({ embeds: [readyEmbed] });

  if (member) {
    const voiceChannel = botServer.channels.cache.find(
      (channel) => channel.name === radioNum && channel.type === "GUILD_VOICE"
    );

    if (voiceChannel) {
      try {
        await member.voice.setChannel(
          botServer.channels.cache.find((channel) => channel.name === radioNum)
        );
        console.log(
          `Moved user ${member.user.tag} to channel ${voiceChannel.name} | Identifier: ${dcIdentifier}`
        );

        emitNet("chat:addMessage", source, {
          args: [translation["you-were-moved"]],
        });

        const logChannel = client.channels.cache.get(logchannelid);

        const readyEmbed = new MessageEmbed()
          .setTitle(translation["succes-moved-title"])
          .setDescription(
            translation["player"] +
              `<@${dcId}> ` +
              translation["succes-moved"] +
              ` ${radioNum}`
          )
          .setFooter(`Discord identifier: ${dcIdentifier}`)
          .setColor("GREEN");
        logChannel.send({ embeds: [readyEmbed] });
      } catch (error) {
        console.error("Error moving user:", error);
      }
    } else {
      console.log(`Voice channel '${radioChan}' not found.`);
    }
  } else {
    console.log("Member does not exist in the guild.");
  }
}


How would I fix this?


a user with Discord ID "1213xxxxxxxxxx" is moved, but a user with "1061xxxxxxxx" isn't.
Was this page helpful?