我终于想通了,让来自YouTube我的不和谐机器人玩音频的方式,使用库“YT-DL”。创建的歌曲队列Discord.js
我已经制作了播放歌曲所需的所有命令。 播放,暂停,停止(结束歌曲)。
我做了一个简单的命令作戏如,播放歌曲,由用户提供的URL。我怎么可能创建一个队列?然后,当当前歌曲结束时,让它播放队列中的下一首歌曲?
我终于想通了,让来自YouTube我的不和谐机器人玩音频的方式,使用库“YT-DL”。创建的歌曲队列Discord.js
我已经制作了播放歌曲所需的所有命令。 播放,暂停,停止(结束歌曲)。
我做了一个简单的命令作戏如,播放歌曲,由用户提供的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 [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();
好吧,这工作。 但是,我有一个问题,我如何每次向列表中添加内容,我们都会执行命令? – Norby
对于数组,'的Array.push()'方法,对于列表中,这将是'list.add()'(或Pascal情况下的方法)。 –
WQYeo
感谢您的帮助! – Norby