在播放音乐的命令中用硬编码 link 替换参数

Replacing argument with hard-coded link in a command to play music

我在尝试使案例陈述起作用时遇到了问题,并且由于这是一个具体问题,我找不到任何足够广泛的搜索词来获得任何类型的良好结果。

我正在尝试让我的 discord 机器人通过在语音频道中播放特定的 youtube 视频来响应命令 "countdown"。

我以前从未在 discord 机器人中做过音乐或语音通道工作,所以我看了一个教程,但它展示了如何使用像 "play" 这样的命令,后面跟着一个 youtube 视频 link。我希望命令没有任何参数并在每次使用 'countdown' 命令时播放特定的 youtube 视频。

这是我现在的,使用命令后需要一个参数。

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;

当我希望机器人播放任何想要的音乐,但我只想要一个与此命令关联的视频时,这非常有用。如有任何帮助,我们将不胜感激。

目前您正在使用一个参数作为视频的 URL。您可以不使用 args[1] 而只是键入 link(如 'https://www.youtube.com/watch?v=G1IbRujko-A')并忽略参数。
请记住,如果您正在检查此命令之前的参数(比如 "Hey, you need this argument to execute the command!"),则应忽略此命令,因为您不会使用任何参数。

希望对您有所帮助:)