0
votes

I am making a simple discord bot with node.js. I got it running and responding but I can't summon it to a voice channel This is the code I am using

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("Give me a link to play");
        return;
      }
      if (!message.member.voiceChannel) {
        message.channel.send("Join a voice channel to play music!");
        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(connection => {
          message.reply("Here I am!");
        });

      break;
  }
});

It always goes to the "Join a voice channel" message, even tho I am in a voice channel.

1

1 Answers

1
votes

As I dived deeper into the documentation I noticed that the code should be

message.member.voice.channel.join()

and not

message.member.voiceChannel.join()