创建歌曲队列 Discord.js
Creating a queue of songs Discord.js
我终于找到了一种让我的 Discord 机器人播放来自 YouTube 的音频的方法,使用库 "yt-dl"。
我已经制作了播放歌曲所需的所有命令。
播放、暂停、停止(结束歌曲)。
我从用户提供的 URL 中为播放做了一个简单的命令,例如播放歌曲。我怎么可能创建一个队列?然后,让它在当前歌曲结束时播放队列中的下一首歌曲?
您可以简单地为您的歌曲创建一个列表,要查看如何创建列表,请查看此 post here。 (您也可以使用数组,如果您只是想限制队列的长度,这可能会有所帮助)
(还有人为javascript创建了一个列表函数,作用类似于.NET的泛型列表,你可以看看here。)
您可能还想创建一个对象来将歌曲详细信息存储在列表中。
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();
我终于找到了一种让我的 Discord 机器人播放来自 YouTube 的音频的方法,使用库 "yt-dl"。
我已经制作了播放歌曲所需的所有命令。 播放、暂停、停止(结束歌曲)。
我从用户提供的 URL 中为播放做了一个简单的命令,例如播放歌曲。我怎么可能创建一个队列?然后,让它在当前歌曲结束时播放队列中的下一首歌曲?
您可以简单地为您的歌曲创建一个列表,要查看如何创建列表,请查看此 post here。 (您也可以使用数组,如果您只是想限制队列的长度,这可能会有所帮助)
(还有人为javascript创建了一个列表函数,作用类似于.NET的泛型列表,你可以看看here。)
您可能还想创建一个对象来将歌曲详细信息存储在列表中。
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();