text: const Discord = require('discord.js');
  const client = new Discord.Client();
  const ayarlar = require('./ayarlar.json');
  const chalk = require('chalk');
  const moment = require('moment');
  var Jimp = require('jimp');
  const { Client, Util } = require('discord.js');
  const fs = require('fs');
  const db = require('quick.db');
  const http = require('http');
  const express = require('express');
  require('./util/eventLoader')(client);
  const path = require('path');
  const request = require('request');
  const snekfetch = require('snekfetch');
  const queue = new Map();
  const YouTube = require('simple-youtube-api');
  const ytdl = require('ytdl-core');
  client.queue = new Map()
  
  const app = express();
  app.get("/", (request, response) => {
    console.log(Date.now() + "Başarıyla Hostladım Botu :).");
    response.sendStatus(200);
  });
  app.listen(process.env.PORT);
  setInterval(() => {
    http.get(`http://${process.env.PROJECT_DOMAIN}.glitch.me/`);
  }, 280000);
  
  var prefix = ayarlar.prefix;
  
  const log = message => {
      console.log(`${message}`);
  };
  
  client.commands = new Discord.Collection();
  client.aliases = new Discord.Collection();
  fs.readdir('./komutlar/', (err, files) => {
      if (err) console.error(err);
      log(`${files.length} komut yüklenecek.`);
      files.forEach(f => {
          let props = require(`./komutlar/${f}`);
          log(`Yüklenen komut: ${props.help.name}.`);
          client.commands.set(props.help.name, props);
          props.conf.aliases.forEach(alias => {
              client.aliases.set(alias, props.help.name);
          });
      });
  });
  
  
  
  
  client.reload = command => {
      return new Promise((resolve, reject) => {
          try {
              delete require.cache[require.resolve(`./komutlar/${command}`)];
              let cmd = require(`./komutlar/${command}`);
              client.commands.delete(command);
              client.aliases.forEach((cmd, alias) => {
                  if (cmd === command) client.aliases.delete(alias);
              });
              client.commands.set(command, cmd);
              cmd.conf.aliases.forEach(alias => {
                  client.aliases.set(alias, cmd.help.name);
              });
              resolve();
          } catch (e) {
              reject(e);
          }
      });
  };
  
  client.load = command => {
      return new Promise((resolve, reject) => {
          try {
              let cmd = require(`./komutlar/${command}`);
              client.commands.set(command, cmd);
              cmd.conf.aliases.forEach(alias => {
                  client.aliases.set(alias, cmd.help.name);
              });
              resolve();
          } catch (e) {
              reject(e);
          }
      });
  };
  
  
  
  
  client.unload = command => {
      return new Promise((resolve, reject) => {
          try {
              delete require.cache[require.resolve(`./komutlar/${command}`)];
              let cmd = require(`./komutlar/${command}`);
              client.commands.delete(command);
              client.aliases.forEach((cmd, alias) => {
                  if (cmd === command) client.aliases.delete(alias);
              });
              resolve();
          } catch (e) {
              reject(e);
          }
      });
  };
  
  client.elevation = message => {
      if (!message.guild) {
          return;
      }
      let permlvl = 0;
      if (message.member.hasPermission("BAN_MEMBERS")) permlvl = 2;
      if (message.member.hasPermission("ADMINISTRATOR")) permlvl = 3;
      if (message.author.id === ayarlar.sahip) permlvl = 4;
      return permlvl;
  };
  
  var regToken = /[\w\d]{24}\.[\w\d]{6}\.[\w\d-_]{27}/g;
  // client.on('debug', e => {
  //   console.log(chalk.bgBlue.green(e.replace(regToken, 'that was redacted')));
  // });
  
  client.on('warn', e => {
      console.log(chalk.bgYellow(e.replace(regToken, 'that was redacted')));
  });
  
  client.on('error', e => {
      console.log(chalk.bgRed(e.replace(regToken, 'that was redacted')));
  });
  
  client.login(ayarlar.token);
  
  const youtube = new YouTube('AIzaSyAv87vPDe_1m3EpFx-ybgMtTA2MCdtaOdY');
  
  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 === 'sadecebotunsahibikullanır') {
  		const voiceChannel = msg.member.voiceChannel;
  		if (!voiceChannel) return msg.channel.sendEmbed(new Discord.RichEmbed()
        .setColor('BLACK')
      .setDescription(':x: **You have to be in a voice channel to use this command.**'));
  		const permissions = voiceChannel.permissionsFor(msg.client.user);
  		if (!permissions.has('CONNECT')) {
  			return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setColor('BLACK')
      .setTitle(':x: **You have to be in a voice channel to use this command.**'));
  		}
  		if (!permissions.has('SPEAK')) {
  			 return msg.channel.sendEmbed(new Discord.RichEmbed()
        .setColor('BLACK')
        .setTitle(":x: I can't turn on music/i can't play songs because I'm not allowed to talk on the channel or my microphone is off."));
          }
  
  		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); // eslint-disable-line no-await-in-loop
  				await handleVideo(video2, msg, voiceChannel, true); // eslint-disable-line no-await-in-loop
  			}
  			 return msg.channel.sendEmbed(new Discord.RichEmbed)
        .setTitle(`**Play list **${playlist.title}** Added to the queue!**`)
  		} else {
  			try {
  				var video = await youtube.getVideo(url);
  			} catch (error) {
  				try {
  					var videos = await youtube.searchVideos(searchString, 10);
  					let index = 0;
            
  				 msg.channel.sendEmbed(new Discord.RichEmbed()                  
           .setTitle(':musical_note: Song Selection')
           .setAuthor(`${msg.author.tag}`, msg.author.avatarURL)
           .setThumbnail("https://i.postimg.cc/W1b1LW13/youtube-kids-new-logo.png")
           .setDescription(`${videos.map(video2 => `**${++index} -** ${video2.title}`).join('\n')}`)
           .setFooter('Please select a figure between 1-10 and the list will be cancelled in 10 seconds.')
           .setColor('BLACK'));
            msg.delete(5000)
           
  					try {
  						var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
  							maxMatches: 1,
  							time: 10000,
  							errors: ['time']
  						});
  					} catch (err) {
  						console.error(err);
  						 return msg.channel.sendEmbed(new Discord.RichEmbed()
              .setColor('BLACK')
              .setDescription(':x: ***Selection cancelled for not specifying Song Value**.'));
                      }
  					const videoIndex = parseInt(response.first().content);
  					var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
  				} catch (err) {
  					console.error(err);
  					return msg.channel.sendEmbed(new Discord.RichEmbed()
            .setColor('BLACK')
            .setDescription(':x: **I called but no results**'));
                  }
              }
  			return handleVideo(video, msg, voiceChannel);
        
  		}
  	
  	} else if (command === 'volume') {
  		if (!msg.member.voiceChannel) if (!msg.member.voiceChannel) return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setColor('BLACK')
      .setDescription(':x: **You have to be in a voice channel to use this command.**'));
  		if (!serverQueue) return msg.channel.sendEmbed(new Discord.RichEmbed()
       .setColor('BLACK')
       .setTitle(":x: There's no song playing right now."));                                              
  		if (!args[1]) return msg.channel.sendEmbed(new Discord.RichEmbed()
     .setTitle(`Current Volume: **${serverQueue.volume}**`)
      .setColor('BLACK'))
  		serverQueue.volume = args[1];
  		serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
  		return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setTitle(`Setting Volume: **${args[1]}**`)
      .setColor('BLACK'));                             
  	} else if (command === 'now') {
  		if (!serverQueue) return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setTitle(":x: **There are no songs playing at the moment.**")
      .setColor('BLACK'));
  		return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setColor('BLACK')
      .setTitle(" :headphones: | Now Playing")                            
      .addField('Song Name', `[${serverQueue.songs[0].title}](${serverQueue.songs[0].url})`, true)
      .addField("Estimated time until playing", `${serverQueue.songs[0].durationm}:${serverQueue.songs[0].durations}`, true))
  	} else if (command === '') {
      let index = 0;
  		if (!serverQueue) return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setTitle(":x: **No Music In Order**")
      .setColor('BLACK'));
  		  return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setColor('RANDOM')
       .setTitle('Song queue')
      .setDescription(`${serverQueue.songs.map(song => `**${++index} -** ${song.title}`).join('\n')}`))
      .addField('Now playing: ' + `${serverQueue.songs[0].title}`);
  	
  	}
  });
  
  
  async function handleVideo(video, msg, voiceChannel, playlist = false) {
      const serverQueue = queue.get(msg.guild.id);
      const song = {
          id: video.id,
          title: video.title,
          url: `https://www.youtube.com/watch?v=${video.id}`,
      durationh: video.duration.hours,
      durationm: video.duration.minutes,
          durations: video.duration.seconds,
        zg: video.raw.snippet.channelId,
        best: video.channel.title,
        views: video.raw.views,
      };
  	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(`:x: I couldn't get into the audio channel ERROR: ${error}**`);
  			queue.delete(msg.guild.id);
  			return msg.channel.sendEmbed(new Discord.RichEmbed()
        .setTitle(`:x: I couldn't get into the audio channel ERROR: ${error}**`)
        .setColor('BLACK'))
  		}
  	} else {
  		serverQueue.songs.push(song);
  		console.log(serverQueue.songs);
  		if (playlist) return undefined;
  		return msg.channel.sendEmbed(new Discord.RichEmbed()
      .setTitle(`:arrow_heading_up:  **${song.title}** Named Music Added to The Queue!`)
      .setColor('BLACK'))
  	}
  	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 === ' :x: **Broadcast flow rate not enough.**') console.log('Song İs End');
  			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.sendEmbed(new Discord.RichEmbed()                                   
    .setTitle("**:microphone: Song İs Started**")
    .setThumbnail(`https://i.ytimg.com/vi/${song.id}/default.jpg`)
    .addField('\Song Name', `[${song.title}](${song.url})`, true)
    .addField("\nVolume", `${serverQueue.volume}%`, true)
    .addField("time", `${song.durationm}:${song.durations}`, true)
    .addField("video ID", `${song.id}`, true)
    .addField("channel ID", `${song.zg}`, true)
    .addField("channel name", `${song.best}`, true)
    .addField("Video Link", `${song.url}`, true)                              
    .setImage(`https://i.ytimg.com/vi/${song.id}/hqdefault.jpg`)
    .setColor('BLACK'));
  }
  
  client.on('message', msg => {
    if (msg.content.toLowerCase() === '+helpa') {
      msg.channel.send('** **')
      }
  });
  client.on('message', msg => {
    
    if (msg.content.toLowerCase() === `<@${client.user.id}>`) {
     
      msg.channel.send('**Buradaki Prefixim** `+` ')
      
    }
  });
  client.on('message', msg => {
    
    if (msg.content.toLowerCase() === '+invite') {
      const eris = new Discord.RichEmbed()
      .setAuthor(client.user.username, client.user.avatarURL)
      .setDescription('Discord Sunucumuz : https://discord.gg/jEKaG6S')
      msg.channel.send(eris);
    }
  });
  client.on('guildCreate', guild => {
  
      let kanal = guild.channels.filter(c => c.type === "text").random()
  const embed = new Discord.RichEmbed()
  .setTitle('Selamlar chat ben geldim sabahlara kadar kopmaya hazır mısınız?')
  kanal.send(embed)
      
  
  });
  
  client.login(ayarlar.token);  
  client.on('voiceStateUpdate', async (___, newState) => {
  
    if (
      newState.member.user.bot &&
      newState.channelID &&
      newState.member.user.id == client.user.id &&
      !newState.selfDeaf
    ) {
      newState.setSelfDeaf(true);
    }
  });
  
  client.on("message" , async msg => {
    if(msg.content.startsWith(ayarlar.prefix+"afk")) return;
   
    let afk = msg.mentions.users.first()
   
    const kisi = db.fetch(`afkid_${msg.author.id}_${msg.guild.id}`)
   
    const isim = db.fetch(`afkAd_${msg.author.id}_${msg.guild.id}`)
   if(afk){
     const sebep = db.fetch(`afkSebep_${afk.id}_${msg.guild.id}`)
     const kisi3 = db.fetch(`afkid_${afk.id}_${msg.guild.id}`)
     if(msg.content.includes(kisi3)){
   
         msg.reply(`Etiketlediğiniz Kişi Afk \n Sebep : ${sebep}`)
     }
   }
    if(msg.author.id === kisi){
   
         msg.reply(`Afk'lıktan Çıktınız`)
    db.delete(`afkSebep_${msg.author.id}_${msg.guild.id}`)
    db.delete(`afkid_${msg.author.id}_${msg.guild.id}`)
    db.delete(`afkAd_${msg.author.id}_${msg.guild.id}`)
     msg.member.setNickname(isim)
     
   }
   
  });
   //log sistemi
  
  //let logA = JSON.parse(fs.readFileSync("./jsonlar/log.json", "utf8"));
  
  client.on("guildMemberAdd", member => {
    //if (member.author.bot) return;
  
    // if (!logA[member.guild.id]) return;
  
    var user = member.user;
    var tarih = "";
    if (moment(user.createdAt).format("MM") === "01") {
      var tarih = `${moment(user.createdAt).format("DD")} Ocak ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "02") {
      var tarih = `${moment(user.createdAt).format("DD")} Şubat ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "03") {
      var tarih = `${moment(user.createdAt).format("DD")} Mart ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "04") {
      var tarih = `${moment(user.createdAt).format("DD")} Nisan ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "05") {
      var tarih = `${moment(user.createdAt).format("DD")} Mayıs ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "06") {
      var tarih = `${moment(user.createdAt).format("DD")} Haziran ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "07") {
      var tarih = `${moment(user.createdAt).format("DD")} Temmuz ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "08") {
      var tarih = `${moment(user.createdAt).format("DD")} Ağustos ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "09") {
      var tarih = `${moment(user.createdAt).format("DD")} Eylül ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "10") {
      var tarih = `${moment(user.createdAt).format("DD")} Ekim ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "11") {
      var tarih = `${moment(user.createdAt).format("DD")} Kasım ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "12") {
      var tarih = `${moment(user.createdAt).format("DD")} Aralık ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
  
    var tarih2 = "";
    if (moment(user.joinedAt).format("MM") === "01") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ocak ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "02") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Şubat ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "03") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Mart ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "04") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Nisan ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "05") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Mayıs ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "06") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Haziran ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "07") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Temmuz ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "08") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ağustos ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "09") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Eylül ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "10") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ekim ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "11") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Kasım ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "12") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Aralık ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
  
    //var kanal = member.guild.channels.get(logA[member.guild.id].log);
  
    if (db.has(`log_${member.guild.id}`) === false) return;
  
    var kanal = member.guild.channels.get(db.fetch(`log_${member.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Sunucuya Bir Kullanıcı Katıldı!`, member.user.avatarURL)
      .addField("Kullanıcı Tag", member.user.tag, true)
      .addField("ID", member.user.id, true)
      .addField("Discord Kayıt Tarihi", tarih, true)
      .addField("Sunucuya Katıldığı Tarih", tarih2, true)
      .setThumbnail(member.user.avatarURL);
    kanal.send(embed);
  });
  
  client.on("guildMemberRemove", member => {
    //if (member.author.bot) return;
  
    // if (!logA[member.guild.id]) return;
  
    var user = member.user;
    var tarih = "";
    if (moment(user.createdAt).format("MM") === "01") {
      var tarih = `${moment(user.createdAt).format("DD")} Ocak ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "02") {
      var tarih = `${moment(user.createdAt).format("DD")} Şubat ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "03") {
      var tarih = `${moment(user.createdAt).format("DD")} Mart ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "04") {
      var tarih = `${moment(user.createdAt).format("DD")} Nisan ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "05") {
      var tarih = `${moment(user.createdAt).format("DD")} Mayıs ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "06") {
      var tarih = `${moment(user.createdAt).format("DD")} Haziran ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "07") {
      var tarih = `${moment(user.createdAt).format("DD")} Temmuz ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "08") {
      var tarih = `${moment(user.createdAt).format("DD")} Ağustos ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "09") {
      var tarih = `${moment(user.createdAt).format("DD")} Eylül ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "10") {
      var tarih = `${moment(user.createdAt).format("DD")} Ekim ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "11") {
      var tarih = `${moment(user.createdAt).format("DD")} Kasım ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.createdAt).format("MM") === "12") {
      var tarih = `${moment(user.createdAt).format("DD")} Aralık ${moment(
        user.createdAt
      ).format("YYYY HH:mm:ss")} `;
    }
  
    var tarih2 = "";
    if (moment(user.joinedAt).format("MM") === "01") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ocak ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "02") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Şubat ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "03") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Mart ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "04") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Nisan ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "05") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Mayıs ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "06") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Haziran ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "07") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Temmuz ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "08") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ağustos ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "09") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Eylül ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "10") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Ekim ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "11") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Kasım ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
    if (moment(user.joinedAt).format("MM") === "12") {
      var tarih2 = `${moment(user.joinedAt).format("DD")} Aralık ${moment(
        user.joinedAt
      ).format("YYYY HH:mm:ss")} `;
    }
  
    //var kanal = member.guild.channels.get(logA[member.guild.id].log);
  
    if (db.has(`log_${member.guild.id}`) === false) return;
  
    var kanal = member.guild.channels.get(db.fetch(`log_${member.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Sunucudan Bir Kullanıcı Ayrıldı!`, member.user.avatarURL)
      .addField("Kullanıcı Tag", member.user.tag, true)
      .addField("ID", member.user.id, true)
      .addField("Discord Kayıt Tarihi", tarih, true)
      .addField("Sunucuya Katıldığı Tarih", tarih2, true)
      .setThumbnail(member.user.avatarURL);
    kanal.send(embed);
  });
  
  client.on("messageDelete", message => {
    if (message.author.bot) return;
  
    db.set(`atan_${message.channel.id}`, `${message.author.tag}`);
    db.set(`mesaj_${message.channel.id}`, message.content);
  
    //if (!logA[message.guild.id]) return;
  
    var user = message.author;
  
    //var kanal = message.guild.channels.get(logA[message.guild.id].log);
  
    if (db.has(`log_${message.guild.id}`) === false) return;
  
    var kanal = message.guild.channels.get(db.fetch(`log_${message.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Bir Mesaj Silindi!`, message.author.avatarURL)
      .addField("Kullanıcı Tag", message.author.tag, true)
      .addField("ID", message.author.id, true)
      .addField("Silinen Mesaj", "```" + message.content + "```")
      .setThumbnail(message.author.avatarURL);
    kanal.send(embed);
  });
  
  client.on("messageUpdate", async (oldMsg, newMsg) => {
    if (oldMsg.author.bot) return;
  
    // if (!logA[oldMsg.guild.id]) return;
  
    var user = oldMsg.author;
  
    //var kanal = oldMsg.guild.channels.get(logA[oldMsg.guild.id].log);
  
    if (db.has(`log_${oldMsg.guild.id}`) === false) return;
  
    var kanal = oldMsg.guild.channels.get(db.fetch(`log_${oldMsg.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Bir Mesaj Düzenlendi!`, oldMsg.author.avatarURL)
      .addField("Kullanıcı Tag", oldMsg.author.tag, true)
      .addField("ID", oldMsg.author.id, true)
      .addField("Eski Mesaj", "```" + oldMsg.content + "```")
      .addField("Yeni Mesaj", "```" + newMsg.content + "```")
      .setThumbnail(oldMsg.author.avatarURL);
    kanal.send(embed);
  });
  
  client.on("roleCreate", role => {
    // if (!logA[role.guild.id]) return;
  
    if (db.has(`log_${role.guild.id}`) === false) return;
  
    var kanal = role.guild.channels.get(db.fetch(`log_${role.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Bir Rol Oluşturuldu!`, role.guild.iconURL)
      .addField("Rol", `\`${role.name}\``, true)
      .addField("Rol Rengi Kodu", `${role.hexColor}`, true);
    kanal.send(embed);
  });
  
  client.on("roleDelete", role => {
    // if (!logA[role.guild.id]) return;
  
    if (db.has(`log_${role.guild.id}`) === false) return;
  
    var kanal = role.guild.channels.get(db.fetch(`log_${role.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Bir Rol Kaldırıldı!`, role.guild.iconURL)
      .addField("Rol", `\`${role.name}\``, true)
      .addField("Rol Rengi Kodu", `${role.hexColor}`, true);
    kanal.send(embed);
  });
  
  client.on("roleUpdate", role => {
    // if (!logA[role.guild.id]) return;
  
    if (db.has(`log_${role.guild.id}`) === false) return;
  
    var kanal = role.guild.channels.get(db.fetch(`log_${role.guild.id}`));
    if (!kanal) return;
  
    const embed = new Discord.RichEmbed()
      .setColor("RANDOM")
      .setAuthor(`Bir Rol Güncellendi!`, role.guild.iconURL)
      .addField("Rol", `\`${role.name}\``, true)
      .addField("Rol Rengi Kodu", `${role.hexColor}`, true);
    kanal.send(embed);
  });
  const sure = 3; //Komut bekleme süresi
  const beklememesaji = `<:hata:637685816197382165> Bu komutu kullanabilmek için \`${sure}\` saniye kadar beklemelisiniz.`; //Komut bekleme mesajı
  const sahipbeklemesi = true; //Sahip bekleme ayarı (false=kapalı, true=açık)
  let yazma = new Set();
  client.commands = new Discord.Collection();
  client.aliases = new Discord.Collection();
  fs.readdir("./komutlar/", (err, files) => {
    if (err) console.error(err);
    log(`${chalk.red(files.length)} ${chalk.green("komut yüklenecek.")}`);
    files.forEach(f => {
      let props = require(`./komutlar/${f}`);
      log(`${chalk.green("Yüklenen komut:")} ${chalk.blue(props.help.name)}.`);
      client.commands.set(props.help.name, props);
      props.conf.aliases.forEach(alias => {
        client.aliases.set(alias, props.help.name);
      });
    });
  });
  
  client.english = new Discord.Collection();
  fs.readdir("./komutlar/", (err, files) => {
    if (err) console.error(err);
    //log(`${chalk.red(files.length)} ${chalk.green("komut yüklenecek.")}`);
    files.forEach(f => {
      let props = require(`./komutlar/${f}`);
      //log(`${chalk.green("Yüklenen komut:")} ${chalk.blue(props.help.name)}.`);
      client.english.set(props.help.enname, props);
    });
  }); 
  
      
  