[英]How to I make my music bot play a finite playlist of songs?
在我的音乐机器人上进一步发展......我试图从让他播放一首歌曲然后离开,到让他播放有限的歌曲列表然后离开。
这不应该与队列混淆 - 歌曲列表是预先确定的和有限的。 它不能被机器人添加或更改,至少目前是这样。 不过,该机器人确实对列表进行了洗牌。
现在的问题是,不是一首一首地播放列表中的歌曲——他播放第一首歌曲,然后是第二首……然后就停止了。
我尝试根据 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("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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.