0
votes
    //music commands

const ytdl = require("ytdl-core");

var servers = {};

let args = message.content.substring(${prefix}.length).split(" ");

if(cmd === ${prefix}play){

function play(connection, message){
    var server = server[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("Pls provide a link!");
    return;
}

if(message.member.voiceChannel){
    message.channel.send("u need 2 be in a channel");
    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.channel.join().then(function(connection){
    play(connection, message);
})

}

this is my music bot code and ive tried alot of solutions but i still cant make it to join my vc and play the music

1

1 Answers

0
votes

message.member.voice.channel.channel does not exist. remove the extra .channel at the end to fix that mistake. Otherwise, it appears message.member.voice.channel is null if that doesnt fix it.

If removing the extra .channel does not fix it, make sure you are in a voice channel.