Javascript 如何使我的音乐机器人播放有限的歌曲播放列表?

Javascript 如何使我的音乐机器人播放有限的歌曲播放列表?,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,进一步发展我的音乐机器人。。。我正试图从让他播放一首歌,然后离开,到让他播放有限的歌曲列表,然后离开 这不应与队列混淆-歌曲列表是预先确定的且有限的。它不能被添加到bot或被bot更改,至少现在是这样。不过机器人确实会洗牌列表 现在的问题是,他没有播放列表中的歌曲,而是一首接一首地播放第一首歌曲,然后播放第二首。。。然后就死了 我曾尝试根据SongToPlay数组的长度设置一个循环,但所做的只是让机器人快速地通过每首歌曲发送垃圾邮件(在前一首歌曲播放之前),然后离开 const connecti

进一步发展我的音乐机器人。。。我正试图从让他播放一首歌,然后离开,到让他播放有限的歌曲列表,然后离开

这不应与队列混淆-歌曲列表是预先确定的且有限的。它不能被添加到bot或被bot更改,至少现在是这样。不过机器人确实会洗牌列表

现在的问题是,他没有播放列表中的歌曲,而是一首接一首地播放第一首歌曲,然后播放第二首。。。然后就死了

我曾尝试根据SongToPlay数组的长度设置一个循环,但所做的只是让机器人快速地通过每首歌曲发送垃圾邮件(在前一首歌曲播放之前),然后离开

const connection = message.member.voice.channel.name;
            const channel = message.member.voice.channel;
            message.channel.send("Now playing Scythe OST in the "+connection+" channel.");
            var SongToPlay = shuffle(testbells);
            channel.join().then(connection => {
                console.log('Now playing '+SongToPlay[0]+'.');
                message.channel.send('Now playing '+SongToPlay[0]+'.');
                const dispatcher = connection.play('./Scythe Digital Edition - Soundtrack/'+SongToPlay[0]+'.mp3');
                dispatcher.setVolume(0.1);
                dispatcher.on("finish", () => {
                    SongToPlay.shift();
                    console.log('Now playing '+SongToPlay[0]+'.');
                    message.channel.send('Now playing '+SongToPlay[0]+'.');
                    connection.play('./Scythe Digital Edition - Soundtrack/'+SongToPlay[0]+'.mp3');
                    dispatcher.setVolume(0.1);
                });
                channel.leave();
            })
            .catch(console.error);
const connection=message.member.voice.channel.name;const channel=message.member.voice.channel;message.channel.send(“现在正在“+连接+”频道播放镰刀OST”);
var SongToPlay=shuffle(testbells);channel.join().then(连接=>{
设currentSong=0;
常数keepPlaying=()=>{
log(`Now playing${SongToPlay[currentSong]}.`);
message.channel.send(`Now playing${SongToPlay[currentSong]}.`);
常数调度员=
connection.play(`./Scythe数字版-Soundtrack/${SongToPlay[currentSong]}.mp3`);
dispatcher.setVolume(0.1);
dispatcher.on(“finish”,()=>{
如果(当前歌曲
const connection=message.member.voice.channel.name;const channel=message.member.voice.channel;message.channel.send(“现在正在“+连接+”频道播放镰刀OST”);
var SongToPlay=shuffle(testbells);channel.join().then(连接=>{
设currentSong=0;
常数keepPlaying=()=>{
log(`Now playing${SongToPlay[currentSong]}.`);
message.channel.send(`Now playing${SongToPlay[currentSong]}.`);
常数调度员=
connection.play(`./Scythe数字版-Soundtrack/${SongToPlay[currentSong]}.mp3`);
dispatcher.setVolume(0.1);
dispatcher.on(“finish”,()=>{
如果(当前歌曲
好的,从我得到的信息来看,npmm中只有一个函数可以让它继续运行。。。有用^.^好的,从我得到的信息来看,npmm中只有一个函数可以让它继续运行。。。有用^^
const connection = message.member.voice.channel.name; const channel = message.member.voice.channel; message.channel.send("Now playing Scythe OST in the "+connection+" channel.");

var SongToPlay = shuffle(testbells); channel.join().then(connection => {
    let currentSong = 0;
    const keepPlaying = () => {
        console.log(`Now playing ${SongToPlay[currentSong]}.`);
        message.channel.send(`Now playing ${SongToPlay[currentSong]}.`);
        const dispatcher =
        connection.play(`./Scythe Digital Edition - Soundtrack/${SongToPlay[currentSong]}.mp3`);
        dispatcher.setVolume(0.1);
        dispatcher.on("finish", () => {
            if (currentSong < SongToPlay.length - 1) {
                currentSong++;
                keepPlaying();
            }

        });
    }
    keepPlaying();
}).catch(console.error);