Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //index.js
- let client = {
- config: require("./config.json"),
- getYouTubeID: require('get-youtube-id'),
- fetchYoutubeInfo: require('youtube-info'),
- ytdl: require('ytdl-core'),
- queue: [],
- isPlaying: false,
- dispatcher: null,
- voiceChannel: null,
- skipReq: 0,
- skippers: {},
- playMusic: async function (id, message) {
- message.member.voiceChannel.join().then(function (connection) {
- stream = client.ytdl("https://www.youtube.com/watch?v=" + id, {
- filter: 'audioonly'
- });
- client.skipReq = 0;
- client.skippers = [];
- dispatcher = connection.playStream(stream);
- });
- },
- getID: async function (str, cb) {
- if (client.isYoutube(str)) {
- cb(client.getYouTubeID(str));
- } else {
- client.search_video(str, function (id) {
- cb(id);
- });
- }
- },
- add_to_queue: async function (strID) {
- if (client.isYoutube(strID)) {
- client.queue.push(client.getID(client.getYouTubeID(strID)));
- } else {
- client.queue.push(strID);
- }
- },
- search_video: async function (query, callback) {
- request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + client.config.yt_api_key, function(error, response, body) {
- var json = JSON.parse(body);
- callback(jsonf.items[0].id.videoId);
- });
- },
- isYoutube: async function (str) {
- return str.toLowerCase().indexOf('youtube.com') > -1;
- }
- }
- //play commnd
- if (client.queue.length > 0 || client.isPlaying) {
- client.getID(args, function (id) {
- client.add_to_queue(id);
- client.fetchYoutubeInfo(id, function (err, videoInfo) {
- if (err) throw new Error(err);
- message.channel.send(`**${videoInfo.title}** has been added to queue!`);
- });
- });
- } else {
- client.isPlaying = true;
- client.getID(args, function (id) {
- client.queue.push('placeholder');
- client.playMusic(id, message);
- client.fetchYoutubeInfo(id, function (err, videoInfo) {
- if (err) throw new Error(err);
- message.channel.send(`Now playing **${videoInfo.title}**`);
- });
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement