const discord = require("discord.js"); const { prefix, token } = require("./config.json"); const ytdl = require("ytdl-core"); const client = new discord.Client(); const queue = new Map(); const search = require("youtube-search"); const chooseArr = ["?", "?", "✂"]; const opts = { maxResults: 1, key: "AIzaSyDm3U6ZBseDE_0lxM5-KW-5-dN3X1jbHnc", type: "video" }; const CLEAR_MESSAGES = "!temizle"; client.on("ready", () => { console.log("Hazırım"); client.user.setActivity(`${prefix}komutlar`); }); client.on("message", async message => { if (message.author.bot) return; if (message.content.toLowerCase() === "!ara") { let embed = new discord.MessageEmbed() .setColor("#fffb00") .setDescription("Eğer Şarkı çalmazsa tekrardan '!ara' yazın.") .setTitle("Şarkı adını girin :mag_right: ") .setFooter("Şarkı aranıyor.") .setTimestamp() let embedMsg = await message.channel.send(embed); let filter = m => m.author.id === message.author.id; let query = await message.channel.awaitMessages(filter, { max: 1 }); let results = await search(query.first().content, opts).catch(err => console.log(err) ); if (results) { let youtubeResults = results.results; let titles = youtubeResults.map(result => { return `${result.link}`; }); console.log(titles); message.delete({ timeout: 3000 }); message.channel.send("!oynat" + " " + titles).then(d_message => { d_message.delete({ timeout: 3000 }); }); if (message.content === "!ara") { const voiceChannel = message.member.voice.channel; voiceChannel.join(); } filter = m => m.author.id === message.author.id && m.content >= 1 && m.content <= youtubeResults.length; let collected = await message.channel.awaitMessages(filter, { maxMatches: 1 }); let selected = youtubeResults[collected.first().content - 1]; embed = new discord.MessageEmbed() .setTitle(`${selected.title}`) .setURL(`${selected.link}`) .setDescription(`${selected.description}`) .setThumbnail(`${selected.thumbnails.default.url}`); message.channel.send(embed); } } }); client.on("message", async message => { if (message.author.bot) return; if (!message.content.startsWith(prefix)) return; const serverQueue = queue.get(message.guild.bot); if (message.content.startsWith(`${prefix}oynat`)) { execute(message, serverQueue); } }); client.on("message", async message => { const serverQueue = queue.get(message.guild.id); if (message.content.startsWith(`${prefix}oynat`)) { execute(message, serverQueue); return; } else if (message.content.startsWith(`${prefix}geç`)) { skip(message, serverQueue); return; } else if (message.content.startsWith(`${prefix}durdur`)) { stop(message, serverQueue); return; } else if (message.content === "!nasılsın") { message.channel.send("İyi değilim ya manitadan ayrıldım"); return; } else if (message.content === "!neden") { message.channel.send("Aldatmış beni") return; } else if (message.content === "!nasıl") { message.channel.send("En yakın arkadaşımla,barda.") return; } else if (message.content ==="!tkm") { async function promptMessage(message, author, time, validReactions) { // We put in the time as seconds, with this it's being transfered to MS time *= 1000; // For every emoji in the function parameters, react in the good order. for (const reaction of validReactions) await message.react(reaction); // Only allow reactions from the author, // and the emoji must be in the array we provided. const filter = (reaction, user) => validReactions.includes(reaction.emoji.name) && user.id === author.id; // And ofcourse, await the reactions return message .awaitReactions(filter, { max: 1, time: time}) .then(collected => collected.first() && collected.first().emoji.name); } const embed = new discord.MessageEmbed() .setColor("#fffff") .setFooter(message.guild.me.displayName, client.user.displayName) .setDescription("Bi tane emoji seçin") .setTimestamp(); const m = await message.channel.send(embed); const tepki = await promptMessage(m, message.author, 30, chooseArr); const botsec = chooseArr[Math.floor(Math.random()* chooseArr.length)]; const result = await getResult(tepki, botsec); await m.reactions.removeAll(); embed .setDescription("") .addField(result, `${tepki} vs ${botsec}`); m.edit(embed); function getResult(me, secim) { if ((me === "?" && secim === "✂") || (me === "?" && secim === "?") || (me === "✂" && secim === "?")) { return "Sen kazandın :confused:"; } else if (me === secim) { return "Berabere :slight_smile:"; } else { return "Kaybettin :kissing_closed_eyes:"; } } } else if (message.content === "!komutlar") { let komut = new discord.MessageEmbed() .setColor("#ff00ea") .setDescription(" **!nasılsın** \n **!geç** \n **!durdur** \n **!ara** \n **!temizle** \n **!oylama** \n **!tkm**") .setTitle("Komutlar :gear:") .setTimestamp(); message.channel.send(komut); } }); async function execute(message, serverQueue) { const args = message.content.split(" "); const voiceChannel = message.member.voice.channel; if (!voiceChannel) return message.channel.send("Lütfen sesli konuşmaya giriniz !"); const permissions = voiceChannel.permissionsFor(message.client.user); if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) { message.channel.send("Bunu yapmaya iznim yok :exclamation:"); } const songInfo = await ytdl.getInfo(args[1]); const song = { title: songInfo.videoDetails.title, url: songInfo.videoDetails.video_url }; if (!serverQueue) { const queueContruct = { textChannel: message.channel, voiceChannel: voiceChannel, connection: null, songs: [], volume: 3, playing: true }; queue.set(message.guild.id, queueContruct); queueContruct.songs.push(song); try { var connection = await voiceChannel.join(); queueContruct.connection = connection; play(message.guild, queueContruct.songs[0]); } catch (err) { console.log(err); queue.delete(message.guild.id); return message.channel.send( "üzgünüm video'yu başlatamadım lütfen tekrar deneyin." ); } } else { let list = new discord.MessageEmbed() .setColor("#db8925") .setTitle(`${song.title} \n Listeye eklendi :white_check_mark:`) .setFooter("Bir şarkı eklendi.") .setTimestamp() serverQueue.songs.push(song); return message.channel.send(list); } } function skip(message, serverQueue) { if (!message.member.voice.channel) return message.channel.send("Lütfen müzik kanalına gir :x:"); if (!serverQueue) return message.channel.send("Geçicek herhangi bir şarkı yok :x:"); serverQueue.connection.dispatcher.end(); } function stop(message, serverQueue) { if (!message.member.voice.channel) return message.channel.send("Durdurmak için lütfen kanala giriniz :x:"); else { let dur = new discord.MessageEmbed() .setColor("#c325db") .setTitle("Şarkıyı durdurdum :octagonal_sign:") .setFooter("Bir şarkı durduruldu.") .setTimestamp() message.channel.send(dur); } serverQueue.songs = []; serverQueue.connection.dispatcher.end(); } function play(guild, song) { const serverQueue = queue.get(guild.id); if (!song) { serverQueue.voiceChannel.leave(); queue.delete(guild.id); return; } const dispatcher = serverQueue.connection .play(ytdl(song.url)) .on("finish", () => { serverQueue.songs.shift(); play(guild, serverQueue.songs[0]); }) .on("error", error => console.error(error)); dispatcher.setVolumeLogarithmic(serverQueue.volume / 5); let sarkı = new discord.MessageEmbed() .setColor("#35d62f") .setTitle("Şarkı çalıyor :musical_note: ") .setDescription(`**${song.title}**`) .setFooter("Bir şarkı çalıyor.") .setTimestamp() serverQueue.textChannel.send(sarkı); } client.on("message", message => { const permissions = message.channel.permissionsFor(message.author); const izin = message.channel.permissionsFor(client.user); if (message.content == CLEAR_MESSAGES) { if (!permissions.has("MANAGE_MESSAGES")) { message.channel.sendMessage( 'Böyle bi iznin yok "' + message.content + '"' ); console.log( "Sorry, you don't have the permission to execute the command \"" + message.content + '"' ); return; } else if (!izin.has("MANAGE_MESSAGES")) { message.channel.send("Benim böyle bir şey yapmaya iznim yok. :x:"); console.log('Böyle bir şey yapmaya iznim yok "' + message.content + '"'); return; } if (message.channel.type === "text") { message.channel.messages .fetch() .then(messages => { message.channel.bulkDelete(messages); let messagesDeleted = messages.array().length; let embed1 = new discord.MessageEmbed() .setColor("#fffb00") .setTitle( "Mesajlar temizlendi toplam temizlenme adeti " + messagesDeleted ) .setFooter("Mesaj temizleme bildirimi.") .setTimestamp() message.channel.send(embed1); console.log( "Deletion of messages successful. Total messages deleted: " + messagesDeleted ); }) .catch(err => { let embed3 = new discord.MessageEmbed() .setColor("#fffb00") .setTitle("Mesajlar silinemedi."); message.channel.send(embed3); console.log("Error while doinng Bulk Deletel"); console.log(err); }); } } }); client.on("message", async message => { if (message.content === "!durdur") { message.react("?"); } if (message.content === "!ara") { message.react("?"); } if (message.content === "!geç") { message.react("⏩"); } }); client.on("message", async message => { if (!message.content.startsWith("!") || message.author.bot) return; const args = message.content.slice("!".length).trim().split(/ +/); const command = args.shift().toLowerCase(); const exampleEmbed = new discord.MessageEmbed() .setColor('#0099ff') .setTitle('Oylama Metni') .setDescription(args.join(" ")) .setTimestamp() .setFooter('Bir oylama oluşturuldu'); if (command === 'oylama') { if (!args.length) { return message.channel.send(`Herhangi bir şey yazmadın, lütfen beni kandırma ${message.author}!`); } let gonder = await message.channel.send(exampleEmbed); await gonder.react("✅"); await gonder.react("❎"); } })