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.')
}
解决方案
嗯,它可以是可变的,有些语音通道允许有些不允许,
所以你需要有一个特定的实例,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.',
},
});
}
推荐阅读
- r - 以 JSON 格式将数据从 MongoDB 导入到 R
- ansible - 获取本地主机 IP 地址并在目标文件中替换为值的 Ansible 任务
- excel - 列出文件夹中的文件 excel onedrive
- firebase-authentication - Google / DialogFlow 上的操作:从没有转换对象的 idToken 获取用户数据
- firebase - Firebase 好友列表关系
- jquery - jquery对图像没有响应的爆炸效果
- javascript - 为什么当我通过 fetch API 请求记录我的 React 状态 setState 时会收到两个响应?
- java - 有没有办法使用 Apache Commons Digester 从 xml 中添加 Arraylist 中键的所有值?
- ios - 图像不是从一个 VC 到另一个 VC
- matlab - 如何在 matlab 或 simulink 中对组合(电气和机械)系统执行鲁棒控制