首页 > 解决方案 > 如何错误处理我的不和谐机器人无法加入语音频道?

问题描述

一些用户收到错误消息Missing Permissions,表示机器人无法定位频道,有三种方法可以修复此错误,下面有两种方法,第一种方法不是最佳选择。第三个选项是下面的答案。

if (!message.guild.me.hasPermission('VIEW_CHANNEL')) {
        return message.channel.send('I can\'t find the voice channel, make sure I have the `View Channel` permission.')
}

// The member has to be in a voice channel
if (!message.member.voice.channel.permissionsFor(<Client>.user).has('VIEW_CHANNEL')) {
        return message.channel.send('I can\'t find the voice channel, make sure I have the `View Channel` permission.')
}

标签: discord.js

解决方案


嗯,它可以是可变的,有些语音通道允许有些不允许,

所以你需要有一个特定的实例,VoiceChannel然后你可以使用.joinable属性

https://discord.js.org/#/docs/main/stable/class/VoiceChannel?scrollTo=joinable

const channel = <VoiceChannel>
if(!channel.joinable) {
       return message.channel.send({
            embed: {
                color: colours.error,
                description: 'I can\'t find the voice channel, make sure I have the `View Channel` permission.',
            },
        });
}

推荐阅读