【发布时间】:2018-02-22 01:37:32
【问题描述】:
我终于找到了一种方法,使用“yt-dl”库让我的 Discord 机器人播放 YouTube 上的音频。
我已经完成了播放歌曲所需的所有命令。 播放、暂停、停止(结束歌曲)。
我从用户提供的 URL 执行了一个简单的播放命令,例如播放歌曲。我怎么可能创建一个队列?然后,让它在当前歌曲结束时播放队列中的下一首歌曲?
【问题讨论】:
我终于找到了一种方法,使用“yt-dl”库让我的 Discord 机器人播放 YouTube 上的音频。
我已经完成了播放歌曲所需的所有命令。 播放、暂停、停止(结束歌曲)。
我从用户提供的 URL 执行了一个简单的播放命令,例如播放歌曲。我怎么可能创建一个队列?然后,让它在当前歌曲结束时播放队列中的下一首歌曲?
【问题讨论】:
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();
【讨论】: