我目前正在制作音乐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");
}
});
答案 0 :(得分:1)