Search code examples
javascriptnode.jsdiscord.jsytdl

I am making a discord music bot with node.js it is kinda working but not joining the vc or playing the song


So the bot gives the voice channel and gives a link warning. However, it doesn't play the song or joins the voice channel.

This is the 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 play the song!")
        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.voiceChannel.join().then(function(connection){
        play(connection, message);
      })


      break;
  }

  
});

I'm not sure what's going wrong; any help would be appreciated. Thanks!


Solution

  • I figured it out I had to install ffmpeg and then it worked