1
votes

I've finally figured out a way of make my Discord bot play audio from YouTube,using the library "yt-dl".

I've made all commands needed for play the song. Play, pause, stop(ends the song).

I did a simple command for the play such as, play the song, from the URL provided by the user. How could I maybe create a queue? And then, make it play the next song in the queue when the current one ends?

2

2 Answers

0
votes

You can simply just create a list for your songs, to check how to create a list, check this post here. (You can also use an array, which may help if you just simply wants to restrict how long your queue can be)

(There is also a guy who created a list function for javascript, it works like .NET's generic list, you can check it out here.)

You might also want to create an object to store your song details to be inside your list.

0
votes
    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();