Facebook
From flextzius, 2 Months ago, written in JavaScript.
Embed
Download Paste or View Raw
Hits: 48
  1. const ytdl = require("ytdl-core")
  2. const ytpl = require("ytpl")
  3.  
  4. exports.run = async (client,message,args,ops) => {
  5.   if(!message.member.voiceChannel) return message.channel.send("Bir ses kanalında olmalısın!")
  6.   if(!args[0]) return message.channel.send("Lütfen bir şarkı url'si veya dı girin!")
  7.  
  8.  
  9.  
  10.   let validate = await ytdl.validateURL(args[0])
  11.   if(!validate) {  
  12.     let commandFile = require("./search.js")
  13.     return commandFile.run(client,message,args,ops)
  14.   }
  15.  
  16.  
  17.   let info = await ytdl.getInfo(args[0])
  18.  
  19.   let data = ops.active.get(message.guild.id) || {};
  20.  
  21.   if(!data.connection) data.connection = await message.member.voiceChannel.join();
  22.   if(!data.queue) data.queue = [];
  23.   data.guildID = message.guild.id;
  24.  
  25.   data.queue.push({
  26.     songTitle: info.title,
  27.     requester: message.author,
  28.     url: args[0],
  29.     announceChannel: message.channel.id
  30.   })
  31.  
  32.   if(!data.dispatcher) play(client,ops,data)
  33.   else{
  34.     message.channel.send(`**${info.title}** sıraya eklendi! ✅ | ${message.author} tarafından istendi.`)
  35.   }
  36.  
  37.   ops.active.set(message.guild.id, data)
  38.  
  39. }
  40.  
  41. async function play(client,ops,data) {
  42.   client.channels.get(data.queue[0].announceChannel).send(`⏯️ Şuan çalınıyor!: **${data.queue[0].songTitle}** | ${data.queue[0].requester} tarafından istendi.`)
  43.   data.dispatcher = await data.connection.playStream(ytdl(data.queue[0].url , {filter:"audioonly"}))
  44.   data.dispatcher.guildID = data.guildID
  45.   data.dispatcher.once("end", function() {
  46.     finish(client,ops,this)
  47.   })
  48. }
  49.  
  50. function finish(client,ops,dispatcher){
  51.   let fetched = ops.active.get(dispatcher.guildID)
  52.   fetched.queue.shift()
  53.  
  54.   if (fetched.queue.length > 0) {
  55.     ops.active.set(dispatcher.guildID, fetched)
  56.     play(client, ops, fetched)
  57.   }else{
  58.     ops.active.delete(dispatcher.guildID)
  59.     let vc = client.guilds.get(dispatcher.guildID).me.voiceChannel
  60.     if(vc) vc.leave()
  61.   }
  62. }