当第一首歌曲流完成时,如何修复 "Stream is not generating quickly enough" 错误?
How to fix "Stream is not generating quickly enough" error when the first song stream finishes?
我在制作一个 discord.js 机器人时偶然发现了从 YouTube 播放流的问题。
在第一个流完成播放调度程序错误后 "Stream is not generating quickly enough" 并且在我重新启动机器人之前不会播放任何其他流。
我正在使用这些模块:
- discord.js@11.4.0
- ffmpeg@0.0.4
- ffmped-二进制文件@3.2.2-3
- opusscript@0.0.6
- ytdl-core@0.25.0
我尝试安装其他版本的 ytdl-core,但这对我没有帮助。
到目前为止,这是我的代码:
const yt = require("ytdl-core");
function play(bot, msg) {
if (msg.guild.queue.songs.length < 1) {
msg.guild.queue.playing = false;
return msg.channel.send("Queue is empty");
}
if (!msg.guild.voiceConnection) {
msg.member.voiceChannel.join().then(con => {
let song = msg.guild.queue.songs.shift();
msg.channel.send(`Playing: **${song.title}**!`);
msg.guild.queue.playing = true;
msg.guild.queue.dispatcher = con.playStream(yt(song.url))
.on("end", reason => {
console.log(reason);
bot.queue[msg.guild.id].dispatcher.stop();
setTimeout(play, 500, bot, msg);
})
.on("error", err => {
console.log(err);
bot.queue[msg.guild.id].dispatcher = null;
setTimeout(play, 500, bot, msg);
});
});
}
}
exports.run = async(bot, msg, args, ops) => {
if (!msg.member.voiceChannel) return msg.channel.send("Connect to a voice channel first!");
if (!args[0]) return msg.channel.send("Specify youtube url first!");
yt.getInfo(args[0], (err, info) => {
if (err) return msg.channel.send(err);
if (!msg.guild.queue) {
msg.guild.queue = {};
msg.guild.queue.playing = false;
msg.guild.queue.songs = [];
msg.guild.queue.dispatcher = null;
}
msg.guild.queue.songs.push({
url: info.video_url,
title: info.title,
requester: msg.author.username
});
if (msg.guild.queue.playing) {
msg.channel.send(`Added **${info.title}** to queue list!`);
} else {
play(bot, msg);
}
});
}
我想最简单的解决方法是使用 discord.js master / v12-dev
可以通过 npm i discordjs/discord.js
安装主版本完全重写了语音功能,当然也有一些重大变化,但总的来说,来自 ytdl 的 stream is not generating fast enough
的问题已在 master 中修复。
我在制作一个 discord.js 机器人时偶然发现了从 YouTube 播放流的问题。
在第一个流完成播放调度程序错误后 "Stream is not generating quickly enough" 并且在我重新启动机器人之前不会播放任何其他流。
我正在使用这些模块:
- discord.js@11.4.0
- ffmpeg@0.0.4
- ffmped-二进制文件@3.2.2-3
- opusscript@0.0.6
- ytdl-core@0.25.0
我尝试安装其他版本的 ytdl-core,但这对我没有帮助。
到目前为止,这是我的代码:
const yt = require("ytdl-core");
function play(bot, msg) {
if (msg.guild.queue.songs.length < 1) {
msg.guild.queue.playing = false;
return msg.channel.send("Queue is empty");
}
if (!msg.guild.voiceConnection) {
msg.member.voiceChannel.join().then(con => {
let song = msg.guild.queue.songs.shift();
msg.channel.send(`Playing: **${song.title}**!`);
msg.guild.queue.playing = true;
msg.guild.queue.dispatcher = con.playStream(yt(song.url))
.on("end", reason => {
console.log(reason);
bot.queue[msg.guild.id].dispatcher.stop();
setTimeout(play, 500, bot, msg);
})
.on("error", err => {
console.log(err);
bot.queue[msg.guild.id].dispatcher = null;
setTimeout(play, 500, bot, msg);
});
});
}
}
exports.run = async(bot, msg, args, ops) => {
if (!msg.member.voiceChannel) return msg.channel.send("Connect to a voice channel first!");
if (!args[0]) return msg.channel.send("Specify youtube url first!");
yt.getInfo(args[0], (err, info) => {
if (err) return msg.channel.send(err);
if (!msg.guild.queue) {
msg.guild.queue = {};
msg.guild.queue.playing = false;
msg.guild.queue.songs = [];
msg.guild.queue.dispatcher = null;
}
msg.guild.queue.songs.push({
url: info.video_url,
title: info.title,
requester: msg.author.username
});
if (msg.guild.queue.playing) {
msg.channel.send(`Added **${info.title}** to queue list!`);
} else {
play(bot, msg);
}
});
}
我想最简单的解决方法是使用 discord.js master / v12-dev
可以通过 npm i discordjs/discord.js
安装主版本完全重写了语音功能,当然也有一些重大变化,但总的来说,来自 ytdl 的 stream is not generating fast enough
的问题已在 master 中修复。