javascript - discord.js(bot)错误:TypeError:connection.playFile不是函数
问题描述
我不明白为什么会有这个错误:
类型错误:connection.playFile 不是函数
我的代码:
if (message.member.voice.channel) {
message.member.voice.channel.join()
.then(connection => {
const dispatcher = connection.playFile(require("path").join(__dirname, './audio.mp3'));
dispatcher.on('start', () => { //not working
dispatcher.setVolume(0.70);
console.log("Playing");
});
dispatcher.on('error', (err) => console.log(err)); //no errors
dispatcher.on('end', end => { //working fine
console.log("Finished");
console.log("End: " + end);
message.member.voiceChannel.leave()
});
});
}
解决方案
您正在使用 discord.js v12,playFile 现在正在播放,更多信息 在这里
message.member.voice.channel.join()
.then(connection => {
const dispatcher = connection.play(require("path").join(__dirname, './audio.mp3'));
应该解决这个问题。
更多信息 - https://discordjs.guide/voice/the-basics.html#the-basics
推荐阅读
- java - 在 UWP UI 上显示最多分钟的系统时间
- firebase - 是否可以检查是否已经值然后不设置该字段?
- python - 有没有更好的方法来使用熊猫的“ffill”方法进行分段填充?
- javascript - 为什么像这样的数组旁边的字符串文字不会在 javascript 中引发语法错误?
- ruby-on-rails - 从 AWS S3 Bucket 获取数据文件并在 Rails 中解析?
- java - 如何解决 Spring Boot 中的“异常评估 SpringEL 表达式”?
- swift - 使用 Swift 在 Core Data 中创建多对多关系
- php - 修复流明分页从零开始
- swift - Swift/Xcode:尝试访问在另一个函数中更新的局部变量
- android - 在 RecyclerAdapter 中隐藏基于上下文的图标,给出空指针