我正试图让它在我的 Discord 机器人中成功循环。我想要的是当命令运行时,机器人从中挑选一首歌曲1-10并播放它(已经完成),并且在播放完这首歌之后,它应该重复挑选一首歌曲并播放它。
我不知道该怎么做。
这是我的代码:
client.on('message', async message => {
var isReady = true;
if (!message.content.startsWith(prefix) || message.author.bot) return;
const args = message.content.slice(prefix.length).split(/ +/);
const command = args.shift().toLowerCase();
if (message.content === `${prefix}KOLARADIO`) {
if (message.member.voice.channel) {
const connection = await message.member.voice.channel.join();
songRandom = Math.floor((Math.random() * 10) + 1);
if (songRandom === 1) {
const dispatcher = connection.play('KOCK_MUSIC/a.mp3')
dispatcher.on('start', () => {
console.log('audio ' + songRandom + ' is playing');
});
dispatcher.on('finish', () => {
console.log('audio has finished playing');
})
dispatcher.on('error', console.error);
}
else if (songRandom === 2) {
const dispatcher = connection.play('KOCK_MUSIC/b.mp3')
dispatcher.on('start', () => {
console.log('audio ' + songRandom + ' is playing');
});
dispatcher.on('finish', () => {
console.log('audio has finished playing');
});
dispatcher.on('error', console.error);
}
else if ...
}
return songRandom;
};
};
});
慕后森
相关分类