text: const Discord = require('discord.js');
  
  const Util = require('discord.js');
  
  const getYoutubeID = require('get-youtube-id');
  
  const fetchVideoInfo = require('youtube-info');
  
  const YouTube = require('simple-youtube-api');
  
  const youtube = new YouTube("AIzaSyAdORXg7UZUo7sePv97JyoDqtQVi3Ll0b8");
  
  const queue = new Map();
  
  const ytdl = require('ytdl-core');
  
  const fs = require('fs');
  
  const gif = require("gif-search");
  
  const client = new Discord.Client({disableEveryone: true});
  
  const prefix = "2";
  /////////////////////////
  ////////////////////////
  
  client.on('message', async msg =>{
  	if (msg.author.bot) return undefined;
      if (!msg.content.startsWith(prefix)) return undefined;
      
      let args = msg.content.split(' ');
  
  	let command = msg.content.toLowerCase().split(" ")[0];
  	command = command.slice(prefix.length)
  
      if(command === `ping`) {
      let embed = new Discord.RichEmbed()
      .setColor(3447003)
      .setTitle("Pong!!")
      .setDescription(`${client.ping} ms,`)
      .setFooter(`Requested by | ${msg.author.tag}`);
      msg.delete().catch(O_o=>{})
      msg.channel.send(embed);
      }
  });
  /////////////////////////
  ////////////////////////
  //////////////////////
  client.on('message', async msg =>{
  	if (msg.author.bot) return undefined;
      if (!msg.content.startsWith(prefix)) return undefined;
      
      let args = msg.content.split(' ');
  
  	let command = msg.content.toLowerCase().split(" ")[0];
  	command = command.slice(prefix.length)
  
      if(command === `avatar`){
  	if(msg.channel.type === 'dm') return msg.channel.send("Nope Nope!! u can't use avatar command in DMs (:")
          let mentions = msg.mentions.members.first()
          if(!mentions) {
            let sicon = msg.author.avatarURL
            let embed = new Discord.RichEmbed()
            .setImage(msg.author.avatarURL)
            .setColor("#5074b3")
            msg.channel.send({embed})
          } else {
            let sicon = mentions.user.avatarURL
            let embed = new Discord.RichEmbed()
            .setColor("#5074b3")
            .setImage(sicon)
            msg.channel.send({embed})
          }
      };
  });
  /////////////////////////
  ////////////////////////
  //////////////////////
  /////////////////////////
  ////////////////////////
  //////////////////////
  
  /////////////////////////
  ////////////////////////
  //////////////////////
  /////////////////////////
  ////////////////////////
  //////////////////////
  client.on('message', async msg => { 
  	if (msg.author.bot) return undefined;
      if (!msg.content.startsWith(prefix)) return undefined;
      
      const args = msg.content.split(' ');
  	const searchString = args.slice(1).join(' ');
      
  	const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
  	const serverQueue = queue.get(msg.guild.id);
  
  	let command = msg.content.toLowerCase().split(" ")[0];
  	command = command.slice(prefix.length)
  
  	if (command === `play`) {
  		const voiceChannel = msg.member.voiceChannel;
          
          if (!voiceChannel) return msg.channel.send("انت لم تدخل روم صوتي");
          
          const permissions = voiceChannel.permissionsFor(msg.client.user);
          
          if (!permissions.has('CONNECT')) {
  
  			return msg.channel.send("ليست لدي صلاحيات للدخول الى الروم");
          }
          
  		if (!permissions.has('SPEAK')) {
  
  			return msg.channel.send("انا لا يمكنني التكلم في هاذه الروم");
  		}
  
  		if (!permissions.has('EMBED_LINKS')) {
  
  			return msg.channel.sendMessage("انا لا املك صلاحيات ارسال روابط")
  		}
  
  		if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
  
  			const playlist = await youtube.getPlaylist(url);
              const videos = await playlist.getVideos();
              
  
  			for (const video of Object.values(videos)) {
                  
                  const video2 = await youtube.getVideoByID(video.id); 
                  await handleVideo(video2, msg, voiceChannel, true); 
              }
  			return msg.channel.send(`**${playlist.title}**, Just added to the queue!`);
  		} else {
  
  			try {
  
                  var video = await youtube.getVideo(url);
                  
  			} catch (error) {
  				try {
  
  					var videos = await youtube.searchVideos(searchString, 5);
  					let index = 0;
                      const embed1 = new Discord.RichEmbed()
                      .setTitle(":mag_right:  YouTube Search Results :")
                      .setDescription(`
                      ${videos.map(video2 => `${++index}. **${video2.title}**`).join('\n')}`)
                      
  					.setColor("#f7abab")
  					msg.channel.sendEmbed(embed1).then(message =>{message.delete(20000)})
  					
  /////////////////					
  					try {
  
  						var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  							maxMatches: 1,
  							time: 15000,
  							errors: ['time']
  						});
  					} catch (err) {
  						console.error(err);
  						return msg.channel.send('لم يتم اختيار الاغنية');
                      }
                      
  					const videoIndex = parseInt(response.first().content);
                      var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
                      
  				} catch (err) {
  
  					console.error(err);
  					return msg.channel.send("I didn't find any results!");
  				}
  			}
  
              return handleVideo(video, msg, voiceChannel);
              
          }
          
  	} else if (command === `skip`) {
  
  		if (!msg.member.voiceChannel) return msg.channel.send("يجب ان تكون في روم صوتي");
          if (!serverQueue) return msg.channel.send("ليست هناك اغاني ليتم التخطي");
  
  		serverQueue.connection.dispatcher.end('تم تخطي الاغنية');
          return undefined;
          
  	} else if (command === `stop`) {
  
  		if (!msg.member.voiceChannel) return msg.channel.send("يجب ان تكون في روم صوتي");
          if (!serverQueue) return msg.channel.send("There is no Queue to stop!!");
          
  		serverQueue.songs = [];
  		serverQueue.connection.dispatcher.end('تم ايقاف الاغنية لقد خرجت من الروم الصوتي');
          return undefined;
          
  	} else if (command === `vol`) {
  
  		if (!msg.member.voiceChannel) return msg.channel.send("يجب ان تكون في روم صوتي");
  		if (!serverQueue) return msg.channel.send('يعمل الامر فقط عند تشغيل مقطع صوتي');
          if (!args[1]) return msg.channel.send(`لقد تم تغير درجة الصوت الى**${serverQueue.volume}**`);
          
  		serverQueue.volume = args[1];
          serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 50);
          
          return msg.channel.send(`درجة الصوت الان**${args[1]}**`);
  
  	} else if (command === `np`) {
  
  		if (!serverQueue) return msg.channel.send('There is no Queue!');
  		const embedNP = new Discord.RichEmbed()
  	    .setDescription(`Now playing **${serverQueue.songs[0].title}**`)
          return msg.channel.sendEmbed(embedNP);
          
  	} else if (command === `queue`) {
  		
  		if (!serverQueue) return msg.channel.send('There is no Queue!!');
  		let index = 0;
  //	//	//
  		const embedqu = new Discord.RichEmbed()
          .setTitle("The Queue Songs :")
          .setDescription(`
          ${serverQueue.songs.map(song => `${++index}. **${song.title}**`).join('\n')}
  **Now playing :** **${serverQueue.songs[0].title}**`)
          .setColor("#f7abab")
  		return msg.channel.sendEmbed(embedqu);
  	} else if (command === `pause`) {
  		if (serverQueue && serverQueue.playing) {
  			serverQueue.playing = false;
  			serverQueue.connection.dispatcher.pause();
  			return msg.channel.send('تم الايقاف');
  		}
  		return msg.channel.send('في انتظار تشغيل المقطع');
  	} else if (command === "resume") {
  
  		if (serverQueue && !serverQueue.playing) {
  			serverQueue.playing = true;
  			serverQueue.connection.dispatcher.resume();
              return msg.channel.send('تم التشغيل');
              
  		}
  		return msg.channel.send('Queue is empty!');
  	}
  
  	return undefined;
  });
  
  async function handleVideo(video, msg, voiceChannel, playlist = false) {
  	const serverQueue = queue.get(msg.guild.id);
  	console.log(video);
  	
  
  	const song = {
  		id: video.id,
  		title: Util.escapeMarkdown(video.title),
  		url: `https://www.youtube.com/watch?v=${video.id}`
  	};
  	if (!serverQueue) {
  		const queueConstruct = {
  			textChannel: msg.channel,
  			voiceChannel: voiceChannel,
  			connection: null,
  			songs: [],
  			volume: 5,
  			playing: true
  		};
  		queue.set(msg.guild.id, queueConstruct);
  
  		queueConstruct.songs.push(song);
  
  		try {
  			var connection = await voiceChannel.join();
  			queueConstruct.connection = connection;
  			play(msg.guild, queueConstruct.songs[0]);
  		} catch (error) {
  			console.error(`I could not join the voice channel: ${error}!`);
  			queue.delete(msg.guild.id);
  			return msg.channel.send(`Can't join this channel: ${error}!`);
  		}
  	} else {
  		serverQueue.songs.push(song);
  		console.log(serverQueue.songs);
  		if (playlist) return undefined;
  		else return msg.channel.send(`**${song.title}**, تمت اضافة المقطع الى قائمة الانتظار `);
  	} 
  	return undefined;
  }
  
  function play(guild, song) {
  	const serverQueue = queue.get(guild.id);
  
  	if (!song) {
  		serverQueue.voiceChannel.leave();
  		queue.delete(guild.id);
  		return;
  	}
  	console.log(serverQueue.songs);
  
  	const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
  		.on('end', reason => {
  			if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
  			else console.log(reason);
  			serverQueue.songs.shift();
  			play(guild, serverQueue.songs[0]);
  		})
  		.on('error', error => console.error(error));
  	dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
  
  	serverQueue.textChannel.send(`**${song.title}**, is now playing!`);
  }
  
  
  client.on('message', message => {
      if (message.content === '2help') {
          let helpEmbed = new Discord.RichEmbed()
          .setTitle('**أوامر الميوزك...**')
          .setDescription
          .addField('2play', 'لتشغيل اغنية')
          .addField('2join', 'دخول رومك الصوتي')
          .addField('2disconnect', 'الخروج من رومك الصوتي')
          .addField('2skip', 'تخطي الأغنية')
          .addField('2pause', 'ايقاف الاغنية مؤقتا')
          .addField('2resume', 'تكملة الاغنية')
          .addField('2queue', 'اظهار قائمة التشغيل')
          .addField('2np', 'اظهار الاغنية اللي انت مشغلها حاليا')
  	.setFooter('============================================')
          .addField('2ghelp', 'اظهاراوامر العامة')
          .setFooter('♡♡♡♡■《《♧♧》》■♡♡♡♡')
        message.channel.send(helpEmbed);
      }
  });
  
  client.on('message', message => {
      if (message.content === '2ghelp') {
          let helpEmbed = new Discord.RichEmbed()
          .setTitle('**أوامر عامة...**')
          .addField('2avatar', "افاتار الشخص المطلوب")
          .addField('2ping', 'معرفة ping البوت')
        message.channel.send(helpEmbed);
      }
  });
  
  client.on('ready', () => {
     console.log(`----------------`);
        console.log(`Desert Bot- Script By : EX Clan`);
          console.log(`----------------`);
        console.log(`ON ${client.guilds.size} Servers '     Script By : EX Clan ' `);
      console.log(`----------------`);
    console.log(`Logged in as ${client.user.tag}!`);
  });
  
  
  
  
  var adminprefix = "2";
  const devs = ['446999223183998987'];
  client.on('message', message => {//Toxic Codes
      var argresult = message.content.split(` `).slice(1).join(' ');//Toxic Code
    if (message.content.startsWith(adminprefix + 'setg')) {
      client.user.setGame(argresult);
        message.channel.send(`**✅   ${argresult}**`)
    } else 
    if (message.content.startsWith(adminprefix + 'setw')) {
    client.user.setActivity(argresult, {type:'WATCHING'});//Toxic Codes
        message.channel.send(`**✅   ${argresult}**`)//Toxic Codes
    } else 
    if (message.content.startsWith(adminprefix + 'setl')) {
    client.user.setActivity(argresult , {type:'LISTENING'});
        message.channel.send(`**✅   ${argresult}**`)//Toxic Codes
    } else 
    if (message.content.startsWith(adminprefix + 'sets')) {
      client.user.setGame(argresult, "https://www.twitch.tv/abdoufersaoui_dz");
        message.channel.send(`**✅**`)//Toxic Codes
    }
    if (message.content.startsWith(adminprefix + 'setname')) {
    client.user.setUsername(argresult).then
        message.channel.send(`Changing The Name To ..**${argresult}** `)
  } else
  if (message.content.startsWith(adminprefix + 'setavatar')) {//Toxic Codes
    client.user.setAvatar(argresult);
      message.channel.send(`Changing The Avatar To :**${argresult}** `);//Toxic Codes
  }
  });//Toxic Codes
  
  client.login(process.env.BOT_TOKEN);
  