我曾尝试在我的代码中为歌曲排队,虽然一次只播放一首歌曲,但它并没有真正起作用 我怎么能解决这个问题? It only plays the second song in that case
async function play(connection, message){
var server = servers[message.guild.id];
//youtube search down
async function searchYouTubeAsync(args) {
var video = await youtube.searchVideos(args.toString().replace(/,/g,' '));
console.log(video.url);
let x = new Discord.MessageEmbed()
.setAuthor(`? Started Playing:`)
.setDescription(`[${video.title}](${video.url})`)
.addField('Duration:', video.length)
.addField('Requested by:', message.author)
.setThumbnail(video.thumbnail)
.setColor(7419530);
message.channel.send(x)
return String(video.url);
}
//youtube search up
var server = servers[message.guild.id];
const stream = ytdl((await searchYouTubeAsync(args)).toString(), { filter: 'audioonly' })
server.dispatcher = connection.play(stream);
server.queue.shift();
server.dispatcher.on("finish", function(){
if(server.queue[0]){
play(connection, message);
}else {
connection.disconnect();
message.channel.send("**Queue Ended, left the VC**✅")
}
})
}
if(!args[0]){
message.channel.send("**Error: Please provide the name/url of the song**❎")
return;
}
if(!message.member.voice.channel){
message.channel.send("**Error: You must be in a voice channel**❎")
return;
}
if(!servers[message.guild.id]) servers[message.guild.id] = {
queue: []
}
var server = servers[message.guild.id];
server.queue.push(args[0]);
if(!message.guild.voiceConnection) message.member.voice.channel.join().then(function(connection){
play(connection, message);
})
我曾尝试将 server.queue[0] 放在 const 流中,但它并没有真正起作用。