2017-09-13 110 views
0

我终于想通了,让来自YouTube我的不和谐机器人玩音频的方式,使用库“YT-DL”。创建的歌曲队列Discord.js

我已经制作了播放歌曲所需的所有命令。 播放,暂停,停止(结束歌曲)。

我做了一个简单的命令作戏如,播放歌曲,由用户提供的URL。我怎么可能创建一个队列?然后,当当前歌曲结束时,让它播放队列中的下一首歌曲?

回答

0

你可以简单地只为您的歌曲列表,检查如何创建一个列表,查看这篇文章here。 (你也可以使用一个数组,如果你只是想限制你的队列的长度,这可能会有所帮助)

(还有一个人为javascript创建了一个列表函数,它的工作原理类似于.NET的通用列表,你可以检查出来here

您可能还需要创建一个对象来存储你的歌曲的细节出现在列表中。

+0

好吧,这工作。 但是,我有一个问题,我如何每次向列表中添加内容,我们都会执行命令? – Norby

+0

对于数组,'的Array.push()'方法,对于列表中,这将是'list.add()'(或Pascal情况下的方法)。 – WQYeo

+0

感谢您的帮助! – Norby

0
var servers = {}; //obj 


    var id = "HgzGwKwLmgM" //"something" 
    //need provide id^

    //example if with array <inside play function> 
    if (!servers[message.guild.id]) servers[message.guild.id] = { 
        queue: [], 
        videodescription: [], 
        videolengh: [], 
        videotitle: [], 
        videothumbnailUrl: [], 
        videourl: [] 
       }; 

    server = servers[message.guild.id]; //method 


    //fetchVideoInfo is part of nmp [email protected] 
    //npm install youtube-info --save 


server.queue.push(id); 

    fetchVideoInfo(id, function (err, videoInfo) { 
    if (err) throw new Error(err); 

    message.reply(' The song: **' + videoInfo.title + "** has been added to the queue list."); 

    server.videolengh.push(videoInfo.duration);//integer 
    server.videothumbnailUrl.push(videoInfo.thumbnailUrl); 
    server.videourl.push(videoInfo.url); 
    server.videotitle.push(videoInfo.title); 
    server.videodescription.push(videoInfo.description); 

    //(videoInfo.description in fetchVideoInfo) returning html 

    }); 

    //        | 
    //later you can call components V like but i will require method 

    console.log(server.queue[0] + "\n"); 
    //or 
    console.log(server.videodescription[0]); 


    //also don't forget to "skip" 
    //example server.queue.shift();