Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const client = new Discord.Client();
- const ytdl = require('ytdl-core');
- const request = require('request');
- const fs = require('fs');
- const getYoutubeID = require('get-youtube-id');
- const fetchVideoInfo = require('youtube-info');
- const http2 = require('http2');
- const yt_api_key = "AIzaSyAyTW85_mLhJCH4WDIlXBHe2UO5RpAVJMQ";
- const prefix = '!!';
- const discord_token = "MzYxMjM1MDg5NTY2NDY2MDQ4.DRKZ1w.AJ11RcdyHd6z10FfeMtb3m3E7K4";
- client.login(discord_token);
- client.on('ready', function() {
- console.log(`Logged in as * [ " ${client.user.username} " ]`);
- console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- console.log('By : #jrjer Team ');
- console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- console.log('~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~');
- });
- var servers = ['351519476879196174','351519138566373386','250642763094294528','372737066536140820','342590736090529794','352297008696000512','','','','','','','','',''];
- var queue = [];
- var guilds = ['',''];
- var queueNames = [];
- var isPlaying = false;
- var dispatcher = null;
- var voiceChannel = null;
- var skipReq = 0;
- var skippers = [];
- var now_playing = [];
- client.on('ready', () => {
- client.user.setGame(` | !!play`,'https://www.twitch.tv/mixclann')
- client.user.setStatus("online");
- });
- client.on('ready', () => {});
- var download = function(uri, filename, callback) {
- request.head(uri, function(err, res, body) {
- console.log('content-type:', res.headers['content-type']);
- console.log('content-length:', res.headers['content-length']);
- request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
- });
- };
- client.on('message', function(message) {
- const member = message.member;
- const mess = message.content.toLowerCase();
- const args = message.content.split(' ').slice(1).join(' ');
- if (mess.startsWith(prefix + 'شغل')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **__يجب ان تكون في روم صوتي__**');
- // if user is not insert the URL or song title
- if (args.length == 0) {
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .setFooter('طلب بواسطة: ' + message.author.tag)
- .setDescription('**قم بإدراج رابط او اسم الأغنيه**')
- message.channel.sendEmbed(play_info)
- return;
- }
- }
- else if (mess.startsWith(prefix + 'تخطي')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** يجب ان تكون في روم صوتي**');
- message.channel.send(':ok:').then(() => {
- skip_song(message);
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- });
- }
- else if (message.content.startsWith(prefix + 'صوت')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- // console.log(args)
- if (args > 100) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
- if (args < 1) return message.channel.send('1 - 100 || **__لا أكثر ولا أقل__**')
- dispatcher.setVolume(1 * args / 50);
- message.channel.sendMessage(`** ${dispatcher.volume*50}% مستوى الصوت **`);
- }
- else if (mess.startsWith(prefix + 'وقف')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- message.channel.send(':ok:').then(() => {
- dispatcher.pause();
- });
- }
- else if (mess.startsWith(prefix + 'كمل')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- message.channel.send(':ok:').then(() => {
- dispatcher.resume();
- });
- }
- else if (mess.startsWith(prefix + 'اطلع')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- message.channel.send(':ok:');
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- }
- else if (mess.startsWith(prefix + 'ادخل')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- message.member.voiceChannel.join().then(message.channel.send(':ok:'));
- }
- else if (mess.startsWith(prefix + 'شغل')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- if (isPlaying == false) return message.channel.send(':anger: || **تم التوقيف**');
- let playing_now_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('تمت إضافة الـأغنيه بقائمة الإنتظار', `**
- ${videoInfo.title}
- **`)
- .setColor("RANDOM")
- .setFooter('طلب بواسطة: ' + message.author.tag)
- .setThumbnail(videoInfo.thumbnailUrl)
- //.setDescription('?')
- message.channel.sendEmbed(playing_now_info);
- }
- });
- function skip_song(message) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **يجب ان تكون في روم صوتي**');
- dispatcher.end();
- }
- function playMusic(id, message) {
- voiceChannel = message.member.voiceChannel;
- voiceChannel.join().then(function(connectoin) {
- let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
- filter: 'audioonly'
- });
- skipReq = 0;
- skippers = [];
- dispatcher = connectoin.playStream(stream);
- dispatcher.on('end', function() {
- skipReq = 0;
- skippers = [];
- queue.shift();
- queueNames.shift();
- if (queue.length === 0) {
- queue = [];
- queueNames = [];
- isPlaying = false;
- }
- else {
- setTimeout(function() {
- playMusic(queue[0], message);
- }, 500);
- }
- });
- });
- }
- function getID(str, cb) {
- if (isYoutube(str)) {
- cb(getYoutubeID(str));
- }
- else {
- search_video(str, function(id) {
- cb(id);
- });
- }
- }
- function add_to_queue(strID) {
- if (isYoutube(strID)) {
- queue.push(getYoutubeID(strID));
- }
- else {
- queue.push(strID);
- }
- }
- function search_video(query, cb) {
- request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
- try {
- var json = JSON.parse(body);
- cb(json.items[0].id.videoId);
- } catch (e) {
- cb('EgqUJOudrcM');
- return;
- console.error(e);
- }
- });
- }
- function isYoutube(str) {
- return str.toLowerCase().indexOf('youtube.com') > -1;
- }
- client.on('ready', () => {});
- var download = function(uri, filename, callback) {
- request.head(uri, function(err, res, body) {
- console.log('content-type:', res.headers['content-type']);
- console.log('content-length:', res.headers['content-length']);
- request(uri).pipe(fs.createWriteStream(filename)).on('close', callback);
- });
- };
- client.on('message', function(message) {
- const member = message.member;
- const mess = message.content.toLowerCase();
- const args = message.content.split(' ').slice(1).join(' ');
- if (mess.startsWith(prefix + 'play')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- // if user is not insert the URL or song title
- if (args.length == 0) {
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .setFooter('request by : ' + message.author.tag)
- .setDescription('**Please enter a song name or Link**')
- message.channel.sendEmbed(play_info)
- return;
- }
- if (queue.length > 0 || isPlaying) {
- getID(args, function(id) {
- add_to_queue(id);
- fetchVideoInfo(id, function(err, videoInfo) {
- if (err) throw new Error(err);
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('The song has been added to the waiting list', `**
- ${videoInfo.title}
- **`)
- .setColor("RANDOM")
- .setFooter('|| ' + message.author.tag)
- .setThumbnail(videoInfo.thumbnailUrl)
- message.channel.sendEmbed(play_info);
- queueNames.push(videoInfo.title);
- now_playing.push(videoInfo.title);
- });
- });
- }
- else {
- isPlaying = true;
- getID(args, function(id) {
- queue.push('placeholder');
- playMusic(id, message);
- fetchVideoInfo(id, function(err, videoInfo) {
- if (err) throw new Error(err);
- let play_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('||** Playing **', `**${videoInfo.title}
- **`)
- .setColor("RANDOM")
- .addField(`By : ${message.author.username}`, `**jrjer Team**`)
- .setThumbnail(videoInfo.thumbnailUrl)
- // .setDescription('?')
- message.channel.sendEmbed(play_info)
- // client.user.setGame(videoInfo.title,'https://www.twitch.tv/Abdulmohsen');
- });
- });
- }
- }
- else if (mess.startsWith(prefix + 'skip')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- message.channel.send(':ok:').then(() => {
- skip_song(message);
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- });
- }
- else if (message.content.startsWith(prefix + 'vol')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- // console.log(args)
- if (args > 100) return message.channel.send('1 - 100')
- if (args < 1) return message.channel.send('1 - 100')
- dispatcher.setVolume(1 * args / 50);
- message.channel.sendMessage(`** ${dispatcher.volume*50}% volume **`);
- }
- else if (mess.startsWith(prefix + 'stop')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- message.channel.send(':ok:').then(() => {
- dispatcher.pause();
- });
- }
- else if (mess.startsWith(prefix + 'ruseme')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** Must BE at a voice channel**');
- message.channel.send(':ok:').then(() => {
- dispatcher.resume();
- });
- }
- else if (mess.startsWith(prefix + 'go')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- message.channel.send(':ok:');
- var server = server = servers[message.guild.id];
- if (message.guild.voiceConnection) message.guild.voiceConnection.disconnect();
- }
- else if (mess.startsWith(prefix + 'join')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || ** Must BE at a voice channel **');
- message.member.voiceChannel.join().then(message.channel.send(':ok:'));
- }
- else if (mess.startsWith(prefix + 'play')) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- if (isPlaying == false) return message.channel.send(':anger: || **Stoped**');
- let playing_now_info = new Discord.RichEmbed()
- .setAuthor(client.user.username, client.user.avatarURL)
- .addField('Playing:', `**
- ${videoInfo.title}
- **`)
- .setColor("RANDOM")
- .setFooter('request By : ' + message.author.tag)
- .setThumbnail(videoInfo.thumbnailUrl)
- //.setDescription('?')
- message.channel.sendEmbed(playing_now_info);
- }
- });
- function skip_song(message) {
- if (!message.member.voiceChannel) return message.channel.send(':no_entry: || **Must BE at a voice channel**');
- dispatcher.end();
- }
- function playMusic(id, message) {
- voiceChannel = message.member.voiceChannel;
- voiceChannel.join().then(function(connectoin) {
- let stream = ytdl('https://www.youtube.com/watch?v=' + id, {
- filter: 'audioonly'
- });
- skipReq = 0;
- skippers = [];
- dispatcher = connectoin.playStream(stream);
- dispatcher.on('end', function() {
- skipReq = 0;
- skippers = [];
- queue.shift();
- queueNames.shift();
- if (queue.length === 0) {
- queue = [];
- queueNames = [];
- isPlaying = false;
- }
- else {
- setTimeout(function() {
- playMusic(queue[0], message);
- }, 500);
- }
- });
- });
- }
- function getID(str, cb) {
- if (isYoutube(str)) {
- cb(getYoutubeID(str));
- }
- else {
- search_video(str, function(id) {
- cb(id);
- });
- }
- }
- function add_to_queue(strID) {
- if (isYoutube(strID)) {
- queue.push(getYoutubeID(strID));
- }
- else {
- queue.push(strID);
- }
- }
- function search_video(query, cb) {
- request("https://www.googleapis.com/youtube/v3/search?part=id&type=video&q=" + encodeURIComponent(query) + "&key=" + yt_api_key, function(error, response, body) {
- try {
- var json = JSON.parse(body);
- cb(json.items[0].id.videoId);
- } catch (e) {
- cb('EgqUJOudrcM');
- return;
- console.error(e);
- }
- });
- }
- function isYoutube(str) {
- return str.toLowerCase().indexOf('youtube.com') > -1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement