有没有办法让我的机器人加入一个语音频道,即使它是空的

is there a way to make my bot joins a voice channel even it is empty

所以我想达到的是,当有人将机器人添加到服务器时,我希望他可以 运行 一个带有语音频道 ID [!join 9562xxxxxxxxxxxxx] 的命令,然后它加入频道并播放music连语音通道都是空的,因为我控制音乐扔我做的代码,所以它有点像广播电台。

我希望我很好地解释了这个问题,我真的是一个初学者程序员。

node v12.22.10

discord.js v12.5.3

我所做的是获取服务器 ID 和频道 ID 并将它们放入代码中。

您不应该再使用 discord.js v12,因为它使用的是旧版本的 Discord API,很快就会弃用。如果您仍想使用 v12,则应执行以下操作:

let args = message.content.substring(1).split(" "); // Array of the arguments

switch(args[0].toLowerCase()){
   case 'join':
      if(!args[1]) return message.channel.send(`Please enter a voice channel id`);
      if(!Number(args[1])) return message.channel.send(`Please enter a valid voice channel id`);
      const vc = message.guild.channels.cache.get(args[1]);
      if(!vc) return message.channel.send(`This voice channel does not exist`);
      if(typeof vc.join !== 'function') return message.channel.send(`The channel is not a voice channel`);
      vc.join().then(connection => {
           const dispatcher = connection.play('Your Song URL');
      }).catch(err => {
         message.channel.send(`There was an error while connecting to the voice channel`);
      });
      break;
}