#Joining the user's current voice channel

6 messages · Page 1 of 1 (latest)

acoustic inlet
#

On [email protected] & node v18.12

I've been trying to create a command that joins whichever channel the user is in.
I keep running into an issue where it doesn't read the user's current voice, instead it thinks "currVoiceChannel" is false.

// Todo: if already in call, reply to user-only, already in call

const { SlashCommandBuilder } = require('discord.js');
const { joinVoiceChannel, getVoiceConnections } = require('@discordjs/voice');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('ejoin')
        .setDescription('Bot will join your current voice.'),
    async execute(interaction) {
        // figure out current voice channel
        const currVoiceChannel = interaction.member.voice.channel;

        // if voicechannel is empty, reply join voice channel, end command
        if (!currVoiceChannel) {
            return interaction.reply('Please join a voice channel.');
        } else {
            console.log('Current VC: ', currVoiceChannel.id);
        }

        // try joining voice channel, or catch the error, end command
        try {
            const connection = joinVoiceChannel({
                channelId: currVoiceChannel.id,
                guildId: currVoiceChannel.guild.id,
                adapterCreator: currVoiceChannel.guild.voiceAdapterCreator,
            });

            console.log(getVoiceConnections());
            await interaction.reply(`Joined: ${currVoiceChannel.name}.`);

        }
        catch (error) {
            console.log(error);
            await interaction.reply('Could not join voice channel.');
        }

        // if called when already in a voice channel, reply already in call, end command

    },
};```
Whenever I join a VC and call the bot it returns "Please join a voice channel".

I've looked at multiple examples and they all use the *If (!currVoiceChannel)*
tawny dewBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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!
nimble magnet
#

Do you have the GuildVoiceStates intent?

acoustic inlet
#

As in the permissions for the bot?

main geyser
#

The intent Discord.GatewayIntentBits.GuildVoiceStates

acoustic inlet
#

I didn't have the intents updated, I only had .Guilds