Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // play.js
- const { Utils } = require("erela.js")
- const { RichEmbed } = require("discord.js")
- module.exports= {
- config: {
- name: "play",
- description: "Plays song/playlist from youtube!",
- usage: "<input>",
- category: "music",
- accessableby: "member",
- aliases: ["p"]
- },
- run: async (bot, message, args) => {
- const { voiceChannel } = message.member;
- if (!voiceChannel) return message.channel.send("You need to be in a voice channel to play music");
- const permissions = voiceChannel.permissionsFor(bot.user);
- if (!permissions.has("CONNECT")) return message.channel.send("I cannot connect to your voice channel, make sure I have permission to");
- if (!permissions.has("SPEAK")) return message.channel.send("I cannot connect to your voice channel, make sure I have permission to");
- if (!args[0]) return message.channel.send("Please provide a song name or link to search");
- const player = bot.music.players.spawn({
- guild: message.guild,
- textChannel: message.channel,
- voiceChannel
- });
- bot.music.search(args.join(" "), message.author).then(async res => {
- switch (res.loadType) {
- case "TRACK_LOADED":
- player.queue.add(res.tracks[0]);
- message.channel.send(`Enqueuing \`${res.tracks[0].title}\` \`${Utils.formatTime(res.tracks[0].duration, true)}`);
- if (!player.playing) player.play()
- break;
- case "SEARCH_RESULT":
- let index = 1;
- const tracks = res.tracks.slice(0, 5);
- const embed = new RichEmbed()
- .setAuthor("Song Selection.", message.author.displayAvatarURL)
- .setDescription(tracks.map(video => `**${index++} -** ${video.title}`))
- .setFooter("Your response time closes within the next 30 seconds. 'Type cancel' to cancel the selction");
- await message.channel.send(embed);
- const collector = message.channel.createMessageCollector(m => {
- return m.author.id === message.author.id && new RegExp(`^([1-5]|cancel)$`, "i").test(m.content)
- }, { time: 30000, max: 1});
- collector.on("collect", m => {
- if(/cancel/i.test(m.content)) return collector.stop("cancelled")
- const track = tracks[Number(m.content) - 1]
- player.queue.add(track)
- message.channel.send(`Enqueuing \`${track.title}\` \`${Utils.formatTime(track.duration, true)}\``)
- if (!player.playing) player.play();
- });
- collector.on("end", (_, reason) => {
- if(["time", "cancelled"].includes(reason)) return message.reply("Cancelled Selection")
- });
- break;
- case "PLAYLIST_LOADED":
- res.playlist.tracks.forEach(track => player.queue.add(track));
- const duration = Utils.formatTime(res.playlist.tracks.reduce((acc, cur) => {duration: acc.duration + cur.duration}).duration, true)
- message.channel.send(`Enqueuing \`${res.playlist.tracks.length}\` \`${duration}\` tracks in playlist \`${res.playlist.info.name}\``)
- if(!player.playing) player.play();
- break;
- }
- }).catch(err => message.channel.send(err.message))
- }
- }
- // ready.js
- const { ErelaClient, Utils } = require("erela.js")
- const { nodes } = require("../../botconfig.json")
- module.exports = async bot => {
- console.log(`${bot.user.username} is online`)
- // bot.user.setActivity("Hello", {type: "STREAMING", url:"https://twitch.tv/Strandable"});
- bot.music = new ErelaClient(bot, nodes)
- .on("nodeError", console.log)
- .on("nodeConnect", () => console.log("Successfully created a new NODE"))
- .on("queneEnd", player => {
- player.textChannel.send("Quene has ended.")
- return bot.music.players.destroy(player.guild.id)
- })
- .on("trackStart", ({textChannel}, {title, duration}) => textChannel.send(`Now playing **${title}** \`${Utils.formatTime(duration, true)}`))
- bot.levels = new Map()
- .set("off", 0.0)
- .set("low", 0.10)
- .set("medium", 0.15)
- .set("high", 0.25)
- let statuses = [
- `V2.2.3 on Tripix Systems`
- ]
- setInterval(function() {
- let status = statuses[Math.floor(Math.random() * statuses.length)];
- bot.user.setActivity(status, {type: "WATCHING"});
- }, 5000)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement