我该如何解决我的不和谐机器人无法加入语音频道的问题?

时间:2020-06-18 19:16:48

标签: discord.js

某些用户收到错误消息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.')
}

1 个答案:

答案 0 :(得分:0)

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

因此,您需要具有特定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.',
            },
        });
}