【问题标题】:Creating a queue of songs Discord.js创建歌曲队列 Discord.js
【发布时间】:2018-02-22 01:37:32
【问题描述】:

我终于找到了一种方法,使用“yt-dl”库让我的 Discord 机器人播放 YouTube 上的音频。

我已经完成了播放歌曲所需的所有命令。 播放、暂停、停止(结束歌曲)。

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

【问题讨论】:

    标签: bots discord


    【解决方案1】:

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

    (还有一个人为javascript创建了一个列表函数,它的工作方式类似于.NET的通用列表,你可以查看here。)

    您可能还想创建一个对象来将歌曲详细信息存储在列表中。

    【讨论】:

    • 好吧,那行得通。但是,我有一个问题,每次我们执行命令时,我如何在列表中添加一些内容?
    • 对于数组,Array.push(<value>) 方法,对于列表,它将是 list.add(<value>)(或方法的帕斯卡大小写)。
    • 感谢您的帮助!
    【解决方案2】:
        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 youtube-info@1.1.1
        //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();
    

    【讨论】:

      猜你喜欢
      • 2020-12-03
      • 1970-01-01
      • 2022-01-01
      • 2020-08-17
      • 2017-08-04
      • 2018-05-09
      • 2019-12-30
      • 2020-07-28
      • 2017-10-11
      相关资源
      最近更新 更多