NO CONNECTION TO VOICE CHANNEL

client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}

// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

message.reply(`Joined ${channel.name}`);

// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.

connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});
client.on('messageCreate', async (message) => {
if (message.author.bot) return;

if (message.content.toLowerCase() === '!join') {
// Check if the author is in a voice channel
if (!message.member.voice.channel) {
message.reply('You need to be in a voice channel to use this command!');
return;
}

// Join the user's voice channel
const channel = message.member.voice.channel;
const connection = joinVoiceChannel({
channelId: channel.id,
guildId: channel.guild.id,
adapterCreator: channel.guild.voiceAdapterCreator,
});

message.reply(`Joined ${channel.name}`);

// You can add additional functionality here, such as playing music, etc.
// For now, let's just log when the bot leaves the channel.

connection.on('stateChange', (state) => {
console.log(`Connection state change: ${state.status}`);
if (state.status === 'Disconnected') {
console.log('Left the channel');
}
});
}
});
1 Reply
d.js toolkit
d.js toolkit13mo 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!
Want results from more Discord servers?
Add your server