2017-09-13 9 views
0

"yt-dl"라이브러리를 사용하여 Discord에서 YouTube 오디오를 재생할 수있는 방법을 알아 냈습니다.노래 큐 만들기 Discord.js

나는 노래를 연주하는 데 필요한 모든 명령을 만들었습니다. 재생, 일시 중지, 정지 (노래 끝내기).

사용자가 제공 한 URL에서 노래를 재생하는 등의 간단한 명령을했습니다. 어떻게 대기열을 만들 수 있습니까? 그런 다음 현재 노래가 끝나면 대기열에서 다음 노래를 재생하게 만드시겠습니까?

답변

0

노래 목록을 만들고 목록을 작성하는 방법을 확인하기 만하면이 게시물 here을 확인할 수 있습니다. 큐를 저장할 수있는 길이를 제한하려는 경우 배열을 사용할 수도 있습니다.

(자바 스크립트의 목록 함수를 만든 사람도 있습니다. NET의 일반 목록처럼 작동합니다 확인해보십시오 here)

노래 세부 정보를 목록에 저장하도록 개체를 만들 수도 있습니다.

+0

좋습니다. 하지만 질문이 있습니다. 매번 목록에 항목을 추가하는 방법은 무엇입니까? – Norby

+0

배열의 경우'Array.push ()'메소드는 list의 경우'list.add ()'(또는 메소드의 파스칼 케이스)가됩니다. – 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();