I'm trying to code my own music bot but it is not joining the voice channel where I'm in. Everything else is working fine. I think that I should install a specific thing using npm but I don't know if that's right or not, i'm not sure so can somebody please tell me what should I do to fix this problem...
Here's My Code :
    client.on('message', message => {
    let args = message.content.substring(prefix.length).split(" ");
    switch (args[0]) {
        case 'play':
            
            function play(connection, message) {
                var server = servers[message.guild.id];
                server.dispatcher = connection.playStream(ytdl(server.queue[0], {filter: "audioonly"}));
                server.queue.shift();
                server.dispatcher.on("end", function() {
                    if(server.queue[0]) {
                        play(connection, message);
                    } else {
                        connection.disconnect();
                    }
                });
            }
            
            
            if(!args[1]) {
                message.channel.send("You need to provide a link!");
                return;
            }
            if(!message.member.voiceChannel) {
                message.channel.send("You must be in a voice channel to use this command!");
                return;
            }
            if(!servers[message.guild.id]) servers[message.guild.id] = {
                queue: []
            }
            var server = servers[message.guild.id];
            server.queue.push(args[1]);
            if(!message.guild.voiceConnection) message.member.voice.channel.join().then(function(connection) {
                play(connection, message);
            })
        break;
    }
});
 
                        
I think you are using the
discord.jsversion 12+, in this version thevoiceConnectionproperty is removed from theGuildMemberclass.You should try the following -