【问题标题】:Music Discord.js bot does not detect voice channelMusic Discord.js 机器人未检测到语音通道
【发布时间】:2020-09-09 00:54:31
【问题描述】:

我目前正在制作音乐 Discord Bot。我的问题出在命令的第一行:即使用户在语音通道中,voiceChannel 也被标记为未定义,机器人返回“您必须在语音通道中才能使用此命令”

client.on("message", async message => {
  if(message.author.bot) return;
  const serverQueue = queue.get(message.guild.id);
  if(message.content.indexOf(PREFIX) !== 0) return;
  const args = message.content.slice(PREFIX.length).trim().split(/ +/g);
  const command = args.shift().toLowerCase();
     if (command === "play" || command === "p") {
        const args = message.content.split(" ");
        const searchString = args.slice(1).join(" ");
        const url = args[1] ? args[1].replace(/<(.+)>/g, "$1") : "";
        const serverQueue = queue.get(message.guild.id);
        const voiceChannel = message.member.voiceChannel;
        if (!voiceChannel) return message.channel.send("You have to be in a voice channel to use this command");
     }
});

【问题讨论】:

    标签: bots discord discord.js


    【解决方案1】:

    看看here

    message.member.voiceChannel;
    

    discord.js 版本 12 及更高版本中不存在

    你需要使用

    message.member.voice.channel.
    

    【讨论】:

      猜你喜欢
      • 2021-07-04
      • 2021-08-18
      • 2021-05-27
      • 1970-01-01
      • 2020-07-17
      • 2020-10-24
      • 2018-09-24
      • 2021-05-01
      • 2021-11-21
      相关资源
      最近更新 更多