Discord Bot音频流提前结束

时间:2019-02-03 20:01:32

标签: javascript node.js youtube discord discord.js

我正在制作一个机器人程序,用于从youtube流音频。大多数情况下,它都可以正常工作,除非我遇到音频中断较早的问题。我认为是因为它获取了所有音频后就无法再读取了,但是它不会播放?无论如何,这是播放功能的代码,我认为这是问题所在。

function play(guild, song, color, msg) {
const serverQueue = queue.get(guild.id);
if (!song) {
    serverQueue.voiceChannel.leave();
    queue.delete(guild.id);
    return;
}
const dispatcher = serverQueue.connection.playStream(ytdl(song.url), {bitrate: 192000 /* 192kbps */})
    .on('end', reason => {
        if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
        else console.log(reason);
            if(queue.get(guild.id).loop === true) {
            serverQueue.songs.push(serverQueue.songs.shift());
            play(guild, serverQueue.songs[0], color, msg);
            }
            if(queue.get(guild.id).loop === false) {
            serverQueue.songs.shift();
            play(guild, serverQueue.songs[0], color, msg);
            }
    })

    .on('error', error => console.error(error));
dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
var embed = new Discord.RichEmbed();
embed.setAuthor(`Start playing`);
embed.setDescription(`**-** [${song.title}](${song.url}) \`${song.time.hours}:${song.time.minutes}:${song.time.seconds}\``);
embed.setColor(color);
embed.setThumbnail(`https://img.youtube.com/vi/${song.id}/maxresdefault.jpg`);
embed.setFooter(`Requested by: ${song.requester.tag}`);
serverQueue.textChannel.send({embed});
}

我想我只需要一种方法就可以使流在完成阅读后继续?任何帮助将不胜感激!

0 个答案:

没有答案