Advertisement
Guest User

Untitled

a guest
Dec 13th, 2019
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // play.js
  2. const { Utils } = require("erela.js")
  3. const { RichEmbed } = require("discord.js")
  4.  
  5. module.exports= {
  6.     config: {
  7.         name: "play",
  8.         description: "Plays song/playlist from youtube!",
  9.         usage: "<input>",
  10.         category: "music",
  11.         accessableby: "member",
  12.         aliases: ["p"]
  13.     },
  14.     run: async (bot, message, args) => {
  15.         const { voiceChannel } = message.member;
  16.         if  (!voiceChannel) return message.channel.send("You need to be in a voice channel to play music");
  17.  
  18.         const permissions = voiceChannel.permissionsFor(bot.user);
  19.         if  (!permissions.has("CONNECT")) return message.channel.send("I cannot connect to your voice channel, make sure I have permission to");
  20.         if  (!permissions.has("SPEAK")) return message.channel.send("I cannot connect to your voice channel, make sure I have permission to");
  21.  
  22.         if  (!args[0]) return message.channel.send("Please provide a song name or link to search");
  23.  
  24.         const player = bot.music.players.spawn({
  25.             guild: message.guild,
  26.             textChannel: message.channel,
  27.             voiceChannel
  28.         });
  29.  
  30.         bot.music.search(args.join(" "), message.author).then(async res => {
  31.             switch (res.loadType) {
  32.                 case "TRACK_LOADED":
  33.                     player.queue.add(res.tracks[0]);
  34.                     message.channel.send(`Enqueuing \`${res.tracks[0].title}\` \`${Utils.formatTime(res.tracks[0].duration, true)}`);
  35.                     if (!player.playing) player.play()
  36.                     break;
  37.                
  38.                 case "SEARCH_RESULT":
  39.                     let index = 1;
  40.                     const tracks = res.tracks.slice(0, 5);
  41.                     const embed = new RichEmbed()
  42.                         .setAuthor("Song Selection.", message.author.displayAvatarURL)
  43.                         .setDescription(tracks.map(video => `**${index++} -** ${video.title}`))
  44.                         .setFooter("Your response time closes within the next 30 seconds. 'Type cancel' to cancel the selction");
  45.  
  46.                     await message.channel.send(embed);
  47.  
  48.                     const collector = message.channel.createMessageCollector(m => {
  49.                         return m.author.id === message.author.id && new RegExp(`^([1-5]|cancel)$`, "i").test(m.content)
  50.                     }, { time: 30000, max: 1});
  51.  
  52.                     collector.on("collect", m => {
  53.                         if(/cancel/i.test(m.content)) return collector.stop("cancelled")
  54.  
  55.                         const track = tracks[Number(m.content) - 1]
  56.                         player.queue.add(track)
  57.                         message.channel.send(`Enqueuing \`${track.title}\` \`${Utils.formatTime(track.duration, true)}\``)
  58.                         if (!player.playing) player.play();
  59.                    
  60.                     });
  61.  
  62.                     collector.on("end", (_, reason) => {
  63.                         if(["time", "cancelled"].includes(reason)) return message.reply("Cancelled Selection")
  64.                     });
  65.                     break;
  66.  
  67.                 case "PLAYLIST_LOADED":
  68.                     res.playlist.tracks.forEach(track => player.queue.add(track));
  69.                     const duration = Utils.formatTime(res.playlist.tracks.reduce((acc, cur) => {duration: acc.duration + cur.duration}).duration, true)
  70.                     message.channel.send(`Enqueuing \`${res.playlist.tracks.length}\` \`${duration}\` tracks in playlist \`${res.playlist.info.name}\``)
  71.                     if(!player.playing) player.play();
  72.                     break;
  73.             }
  74.         }).catch(err => message.channel.send(err.message))
  75.     }
  76. }
  77. // ready.js
  78. const { ErelaClient, Utils } = require("erela.js")
  79. const { nodes } = require("../../botconfig.json")
  80. module.exports = async bot => {
  81.      console.log(`${bot.user.username} is online`)
  82.     // bot.user.setActivity("Hello", {type: "STREAMING", url:"https://twitch.tv/Strandable"});
  83.    
  84.     bot.music = new ErelaClient(bot, nodes)
  85.     .on("nodeError", console.log)
  86.     .on("nodeConnect", () => console.log("Successfully created a new NODE"))
  87.     .on("queneEnd", player => {
  88.         player.textChannel.send("Quene has ended.")
  89.         return bot.music.players.destroy(player.guild.id)
  90.     })
  91.     .on("trackStart", ({textChannel}, {title, duration}) => textChannel.send(`Now playing **${title}** \`${Utils.formatTime(duration, true)}`))
  92.  
  93.     bot.levels = new Map()
  94.     .set("off", 0.0)
  95.     .set("low", 0.10)
  96.     .set("medium", 0.15)
  97.     .set("high", 0.25)
  98.  
  99.     let statuses = [
  100.         `V2.2.3 on Tripix Systems`
  101.     ]
  102.  
  103.     setInterval(function() {
  104.         let status = statuses[Math.floor(Math.random() * statuses.length)];
  105.         bot.user.setActivity(status, {type: "WATCHING"});
  106.  
  107.     }, 5000)
  108.  
  109. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement