无法离开语音频道

时间:2019-02-14 17:03:38

标签: javascript discord

我的机器人无法离开语音通道,但可以加入任何人。我有2个代码,一个是“ leave”,另一个是“ stopstream”,它说“无法读取未定义的属性'channelID'”和“((node:11416)UnhandledPromiseRejectionWarning:TypeError:无法读取未定义的属性'voiceChannel'” “带有一个复杂的代码

我尝试使用不同的代码,一个比另一个复杂。并把“ const ytdl = require('ytdl-core'); const streamOptions = {搜寻:0,音量:1};”。

//leave

const ytdl = require('ytdl-core');
const streamOptions = { seek: 0, volume: 1 };

exports.run = async (client, message, args, ops) => {

   if (!message.member.voiceChannel) return message.channel.send('Please connect to a voice chanel, don\'t be afraid my child. Share you beautiful voice.');

   if (!message.guild.mne.voiceChannel) return message.channel.send('Sorry, I\'m not connected to the guild.');

   if (message.guild.me.voiceChannelID !== message.member.voiceChannelID) return message.chanel.send('Sorry, you aren\t connected to the same channel, I\'ll give you some PeterFriffinCoins, for free.');

   message.guild.me.voiceChannel.leave();

   message.channel.send('Leaving Channel... I\'m a free elf...')
}


//stopstream

exports.run = (client, message, args) => {

    client.leaveVoiceChannel(message.member.voiceState.channelID);
    message.channel.send('Thanks for tuning in!');
}

1 个答案:

答案 0 :(得分:0)

在离开频道命令中尝试

let authorVoiceChannel = message.member.voiceChannel;
if(!authorVoiceChannel) return message.channel.send("You are not in a voice channel")
if(authorVoiceChannel.id !== client.voiceChannel.id) return message.channel.send("We're not in the same voice channel")

authorVoiceChannel.leave()

message.channel.send("I left voice channel")