0
votes

I'm having trouble trying to get a case statement to work, and since this is a specific question I can't find any search terms broad enough to get any kinds of good results.

I'm trying to get my discord bot to respond to a command "countdown" by playing a specific youtube video in a voice channel.

I've never done music or voice channel work in discord bots before, so I watched a tutorial, but it showed how to use a command like "play" followed by an argument that is a youtube video link. I want the command to not have any args and play a specific youtube video each time that 'countdown' command is used.

Here is what I have now, which requires an argument after the command is used.

case "countdown":
  if (!message.member.voiceChannel) {
    message.channel.sendMessage("You must be in a voice channel to initiate a countdown.");
    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;

This is good for when I want the bot to play any music desired, but I just want one video associated with this command. Any help would be appreciated, thanks.

1

1 Answers

0
votes

At the moment you're using an argument as the URL for the video. Instead of using args[1] you could just type your link (like 'https://www.youtube.com/watch?v=G1IbRujko-A') and ignore the argument.
Keep in mind that if you're checking the arguments before this command (to say stuff like "Hey, you need this argument to execute the command!") you should ignore this one since you won't be using any argument.

Hope this can help you :)