Anton
Anton
DIAdiscord.js - Imagine an app
Created by Anton on 4/15/2024 in #djs-questions
(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.
4 replies
DIAdiscord.js - Imagine an app
Created by Anton on 4/12/2024 in #djs-questions
What Discord.js version works on 16.9.1
Hi! I'm trying to make a Discord bot, which is going be hosted by a FiveM server. Since the latest FiveM Node.js version is 16.9.1, I want to find out which Discord.js version works with that. (Moving the user from 1 voice channel to another is a huge must). Slash commands would be nice but is not a direct must.
4 replies