Bot is not joining voice channel after executing function in voiceStateUpdate event

After I made a function that is responsible for automatically playing the radio when a user joins the channel, the bot does not join the channel at all despite the variables being correctly defined. Debugging showed nothing (I tried logging connection, player, stream, resource sequentially), however everything seems to be used correctly. I am using almost the same code in the radio.ts command which is responsible for starting the radio manually, where everything works correctly. The only thing that changes is adapterCreator which I currently think is the problem in my function.
16 Replies
d.js toolkit
d.js toolkit8mo 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
Korrumz2
Korrumz2OP8mo ago
and also idk why in the @discordjs/voice documentation basically every page I go to returns a 404 error and no, I have no error
ThePedroo
ThePedroo8mo ago
I've never used @djs/voice with djs, but you should use discord.js to join it Something that can also be happening is channel.id not exist, or settings.radioStation not exist too
Korrumz2
Korrumz2OP8mo ago
they both exist
ThePedroo
ThePedroo8mo ago
I'll let someone more experienced with djs/voice with djs handle this
Korrumz2
Korrumz2OP8mo ago
wait, it's not like these methods are only in @discord.js/voice? in the docs only they are there
ThePedroo
ThePedroo8mo ago
Usually we handle voice joining manually when not using with djs or being an independent node Unless you are not calling startRadio in voiceStateUpdate, I'm unsure why it's not joining
Korrumz2
Korrumz2OP8mo ago
if I hadn't called it in voiceStateUpdate, I wouldn't have got response from console.logs
ThePedroo
ThePedroo8mo ago
Well, you only provided half of the voiceStateUpdate, hard to make any assumptions But this is most likely to be an issue on how you're using joinVChannel function if it's being reached
Korrumz2
Korrumz2OP8mo ago
import { type ColorResolvable, EmbedBuilder } from "discord.js";
import { startRadio } from "utils/startRadio";
export async function voiceStateUpdate(client, oldState, newState) {
let description = "";
let color = "";

const embed = new EmbedBuilder().setTimestamp();

if (oldState.channel !== newState.channel) {
if (!oldState.channel && newState.channel) {
description = `User ${newState.member.user.username} **joined channel** <#${newState.channel.id}> \`[${newState.channel.name}]\``;
color = "Green";

await startRadio(client, newState.guildId)
} else if (oldState.channel && !newState.channel) {
description = `User ${newState.member.user.username} **left channel** <#${oldState.channel.id}> \`[${oldState.channel.name}]\``;
color = "Green";
} else {
description = `User ${newState.member.user.username} **moved from** <#${oldState.channel.id}> \`[${newState.channel.name}]\` to <#${newState.channel.id}> [${newState.channel.name}]`;
color = "Yellow";
}
} else {
const availableStateKeys = {
serverDeaf: "defeaned (by admin)",
serverMute: "muted (by admin)",
selfDeaf: "deafened",
selfMute: "muted",
selfVideo: "started video",
};
for (const key in availableStateKeys) {
if (oldState[key] !== newState[key]) {
embed.setDescription(
`User ${newState.member.user.username} was **${
newState[key] ? "un" : ""
}${availableStateKeys[key]}** in \`${
oldState.channel.name
}\``,
);
}
}
}

if (description) {
embed.setDescription(description);
embed.setColor(color as ColorResolvable);

client.channels.cache
.get("1071407744894128178")
.send({ embeds: [embed] });
}
}
import { type ColorResolvable, EmbedBuilder } from "discord.js";
import { startRadio } from "utils/startRadio";
export async function voiceStateUpdate(client, oldState, newState) {
let description = "";
let color = "";

const embed = new EmbedBuilder().setTimestamp();

if (oldState.channel !== newState.channel) {
if (!oldState.channel && newState.channel) {
description = `User ${newState.member.user.username} **joined channel** <#${newState.channel.id}> \`[${newState.channel.name}]\``;
color = "Green";

await startRadio(client, newState.guildId)
} else if (oldState.channel && !newState.channel) {
description = `User ${newState.member.user.username} **left channel** <#${oldState.channel.id}> \`[${oldState.channel.name}]\``;
color = "Green";
} else {
description = `User ${newState.member.user.username} **moved from** <#${oldState.channel.id}> \`[${newState.channel.name}]\` to <#${newState.channel.id}> [${newState.channel.name}]`;
color = "Yellow";
}
} else {
const availableStateKeys = {
serverDeaf: "defeaned (by admin)",
serverMute: "muted (by admin)",
selfDeaf: "deafened",
selfMute: "muted",
selfVideo: "started video",
};
for (const key in availableStateKeys) {
if (oldState[key] !== newState[key]) {
embed.setDescription(
`User ${newState.member.user.username} was **${
newState[key] ? "un" : ""
}${availableStateKeys[key]}** in \`${
oldState.channel.name
}\``,
);
}
}
}

if (description) {
embed.setDescription(description);
embed.setColor(color as ColorResolvable);

client.channels.cache
.get("1071407744894128178")
.send({ embeds: [embed] });
}
}
just I don't think the rest is necessary lol i fixed it somehow xDD i replaced guildId with guild.id
ThePedroo
ThePedroo8mo ago
💀 LMAO Please mark this as solved btw
Korrumz2
Korrumz2OP8mo ago
Yeah
ThePedroo
ThePedroo8mo ago
?
Korrumz2
Korrumz2OP8mo ago
I'll close
ThePedroo
ThePedroo8mo ago
Just click this button
Korrumz2
Korrumz2OP8mo ago
oh nvm
Want results from more Discord servers?
Add your server