Discord.js ytdl Error: input stream: Status code: 416
Discord.js ytdl Error: input stream: Status code: 416
我有一个使用 ytdl 的音乐 Discord 机器人,偶尔,歌曲会随机停止并输出此错误:
Error: input stream: Status code: 416
这是我的 playSong 函数代码
static playSong(queue, message) {
const classThis = this;
queue[0].voiceChannel
.join()
.then(function(connection) {
const dispatcher = connection.play(ytdl(queue[0].url, {quality: 'highestaudio'}))
.on('start', function() {
message.guild.musicData.songDispatcher = dispatcher;
dispatcher.setVolume(message.guild.musicData.volume);
const videoEmbed = new Discord.MessageEmbed()
.setThumbnail(queue[0].thumbnail)
.setColor(embedSettings.color)
.addField('Now Playing', `${queue[0].title} (${queue[0].url})`)
.addField('Duration', queue[0].duration)
.setFooter(embedSettings.footer, embedSettings.footer_url);
if (queue[1]) videoEmbed.addField('Next Song:', queue[1].title);
message.say(videoEmbed);
message.guild.musicData.nowPlaying = queue[0];
return queue.shift();
})
.on('finish', function() {
if (queue.length >= 1) {
return classThis.playSong(queue, message);
} else {
message.guild.musicData.isPlaying = false;
message.guild.musicData.nowPlaying = null;
message.guild.musicData.songDispatcher = null;
if (message.guild.me.voice.channel) {
return message.guild.me.voice.channel.leave();
}
}
})
}
当我将机器人转移到 Discord Bot 托管服务时,错误发生的频率降低但仍然发生。这是我的代码问题,还是与 YouTube 的连接问题 API?
我使用以下方法解决了这个问题:
const dispatcher = connection.play(ytdl(queue[0].url, {
quality: 'highestaudio',
highWaterMark: 1 << 25
}))
所以,对你来说:
static playSong(queue, message) {
const classThis = this;
queue[0].voiceChannel
.join()
.then(function(connection) {
const dispatcher = connection.play(ytdl(queue[0].url, {quality: 'highestaudio', highWaterMark: 1 << 25 }))
.on('start', function() {
message.guild.musicData.songDispatcher = dispatcher;
dispatcher.setVolume(message.guild.musicData.volume);
const videoEmbed = new Discord.MessageEmbed()
.setThumbnail(queue[0].thumbnail)
.setColor(embedSettings.color)
.addField('Now Playing', `${queue[0].title} (${queue[0].url})`)
.addField('Duration', queue[0].duration)
.setFooter(embedSettings.footer, embedSettings.footer_url);
if (queue[1]) videoEmbed.addField('Next Song:', queue[1].title);
message.say(videoEmbed);
message.guild.musicData.nowPlaying = queue[0];
return queue.shift();
})
.on('finish', function() {
if (queue.length >= 1) {
return classThis.playSong(queue, message);
} else {
message.guild.musicData.isPlaying = false;
message.guild.musicData.nowPlaying = null;
message.guild.musicData.songDispatcher = null;
if (message.guild.me.voice.channel) {
return message.guild.me.voice.channel.leave();
}
}
})
}
我有一个使用 ytdl 的音乐 Discord 机器人,偶尔,歌曲会随机停止并输出此错误:
Error: input stream: Status code: 416
这是我的 playSong 函数代码
static playSong(queue, message) {
const classThis = this;
queue[0].voiceChannel
.join()
.then(function(connection) {
const dispatcher = connection.play(ytdl(queue[0].url, {quality: 'highestaudio'}))
.on('start', function() {
message.guild.musicData.songDispatcher = dispatcher;
dispatcher.setVolume(message.guild.musicData.volume);
const videoEmbed = new Discord.MessageEmbed()
.setThumbnail(queue[0].thumbnail)
.setColor(embedSettings.color)
.addField('Now Playing', `${queue[0].title} (${queue[0].url})`)
.addField('Duration', queue[0].duration)
.setFooter(embedSettings.footer, embedSettings.footer_url);
if (queue[1]) videoEmbed.addField('Next Song:', queue[1].title);
message.say(videoEmbed);
message.guild.musicData.nowPlaying = queue[0];
return queue.shift();
})
.on('finish', function() {
if (queue.length >= 1) {
return classThis.playSong(queue, message);
} else {
message.guild.musicData.isPlaying = false;
message.guild.musicData.nowPlaying = null;
message.guild.musicData.songDispatcher = null;
if (message.guild.me.voice.channel) {
return message.guild.me.voice.channel.leave();
}
}
})
}
当我将机器人转移到 Discord Bot 托管服务时,错误发生的频率降低但仍然发生。这是我的代码问题,还是与 YouTube 的连接问题 API?
我使用以下方法解决了这个问题:
const dispatcher = connection.play(ytdl(queue[0].url, {
quality: 'highestaudio',
highWaterMark: 1 << 25
}))
所以,对你来说:
static playSong(queue, message) {
const classThis = this;
queue[0].voiceChannel
.join()
.then(function(connection) {
const dispatcher = connection.play(ytdl(queue[0].url, {quality: 'highestaudio', highWaterMark: 1 << 25 }))
.on('start', function() {
message.guild.musicData.songDispatcher = dispatcher;
dispatcher.setVolume(message.guild.musicData.volume);
const videoEmbed = new Discord.MessageEmbed()
.setThumbnail(queue[0].thumbnail)
.setColor(embedSettings.color)
.addField('Now Playing', `${queue[0].title} (${queue[0].url})`)
.addField('Duration', queue[0].duration)
.setFooter(embedSettings.footer, embedSettings.footer_url);
if (queue[1]) videoEmbed.addField('Next Song:', queue[1].title);
message.say(videoEmbed);
message.guild.musicData.nowPlaying = queue[0];
return queue.shift();
})
.on('finish', function() {
if (queue.length >= 1) {
return classThis.playSong(queue, message);
} else {
message.guild.musicData.isPlaying = false;
message.guild.musicData.nowPlaying = null;
message.guild.musicData.songDispatcher = null;
if (message.guild.me.voice.channel) {
return message.guild.me.voice.channel.leave();
}
}
})
}