Как заставить мой musi c бот проигрывать конечный плейлист с песнями? - PullRequest
0 голосов
/ 01 августа 2020

Дальнейшее развитие моего musi c бота ... Я пытаюсь перейти от того, чтобы он играл одну песню, а затем ушел, к тому, чтобы он сыграл конечный список песен, а затем ушел.

Не путать с очередью - список песен предопределен и конечен. Он не может быть добавлен или изменен ботом, по крайней мере, в настоящее время. Однако бот ДЕЙСТВИТЕЛЬНО перемешивает список.

Проблема сейчас в том, что вместо того, чтобы проигрывать песни в списке, одну за другой - он проигрывает первую песню, затем вторую ... и останавливается.

Я попытался настроить al oop на основе длины массива 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);

1 Ответ

2 голосов
/ 02 августа 2020
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);
...