javascript - connection.playStream 不是函数
问题描述
我知道关于这个主题有很多问题,但我浏览了所有这些问题,但似乎没有一个答案能解决我的问题。我只是为了好玩而创建了一个 Discord 机器人,我几乎从未使用过 JavaScript 编程,但我想尝试一下。
我的代码如下所示:
var url = "https://www.youtube.com/watch?v=HHv-s2OqYpw"
if(!message.member.voice.channel){
message.channel.send("Join a voice channel.");
return
} else {
vc = message.member.voice.channel;
connection = await vc.join();
isValid = ytdl.validateURL(url);
if(!isValid){
message.channel.send("The url you gave doesn't exist");
} else {
const stream = ytdl(url, {filter: "audioonly"});
const dispatcher = connection.playStream(stream)
dispatcher.on("end", function() {
vc.leave()
message.channel.send("Done playing the only music I can play lol")
})
我可以这样做,它可以播放更多歌曲,但我只希望它播放这首歌曲,并且在终端中我收到此错误:
connection.playStream is not a function
我确实安装了 ytdl-core 和 opusscript,它们都有最新版本。我尝试了很多不同的方式来做这件事,这真的让我很恼火,因为我无法弄清楚问题是什么。抱歉英语不好,感谢帮助我的人。祝你今天过得愉快!
解决方案
https://discord.js.org/#/docs/main/stable/class/VoiceConnection?scrollTo=play
正如你所看到的,有一个VoiceConnection#play()
方法,因为你很可能在 v12 上,这就是你的方法重新寻找。
const stream = ytdl(url, options);
const dispatcher = connection.play(stream);
推荐阅读
- sql - 如何应用自由文本搜索来查看子查询
- docker - 502 Bad Gateway Docker Nginx with SSL Certbot 但 Http 工作
- python - 如何在 Django Elasticsearch 中映射关键字字段?
- android-studio - Android Studio 4.2 @Generated 未找到
- python - 根据值 pandas 选择行
- php - 全文搜索是否可以使用 MySql + Laravel 5.7 搜索字符串的一部分
- python - 为什么 tkinter 小部件不会随画布滚动?
- reactjs - 为什么在全局管理状态时组件内部出现无限循环?
- firebase - [FirebaseError:Firebase:名为“[DEFAULT]”的 Firebase 应用程序已存在(应用程序/重复应用程序)。]
- git - 还原合并还原