(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.");
}
}
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.
3 Replies
d.js toolkit
d.js toolkit5mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Anton
Anton5mo ago
No description
Anton
Anton5mo ago
Nvm, I realized what was wrong.
Want results from more Discord servers?
Add your server