Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require('discord.js');
- const Lavalink = require('discord.js-lavalink');
- const snekfetch = require("snekfetch");
- const config = require("./config.js");
- async function start() {
- const language = {
- noMusicPlaying: "No music is playing!"
- }
- const client = new Discord.Client();
- client.queue = [];
- client.on('ready', () => {
- client.nodes = [
- { host: "localhost", port: 8341, region: "us", password: "0751" }
- ];
- client.manager = new Lavalink.PlayerManager(client, client.nodes, {
- user: client.user.id,
- shards: 0
- });
- console.log(`Ready on ${client.guilds.size} guilds`);
- });
- async function getSongs(string) {
- const res = await snekfetch.get(`http://${client.nodes[0].host}:${client.nodes[0].port}/loadtracks?identifier=${string}`)
- .set("Authorization", client.nodes[0].password)
- .catch(err => {
- console.error(err);
- return null;
- });
- if (!res) throw "There was an error, try again";
- if(!res.body.tracks[0]) return "Error";
- console.log(res)
- return res.body;
- }
- async function play(client, msg) {
- try {
- let queue = client.queue[msg.guild.id];
- const player = await client.manager.join({
- guild: msg.guild.id,
- channel: msg.member.voiceChannelID,
- host: `${client.nodes[0].host}`
- });
- console.log(client.queue[msg.guild.id][0]);
- player.play(client.queue[msg.guild.id][0].track);
- player.once("end", async data => {
- queue.shift()
- if(client.queue[msg.guild.id][0]) {
- setTimeout(() => {
- play(client, msg);
- msg.channel.send(`Playing: ${client.queue[msg.guild.id][0].info.title}`);
- }, 200)
- }else {
- msg.channel.send("Queue is empty");
- await client.manager.leave(msg.guild.id);
- }
- });
- console.log(queue)
- }catch(err) {
- console.log(err);
- }
- }
- async function getSong(string, msg) {
- getSongs(string).then(async song => {
- if(!song) return msg.reply("No tracks were found");
- client.queue[msg.guild.id].push(song.tracks[0]);
- const player = client.manager.get(msg.guild.id);
- if(!player) {
- play(client, msg);
- msg.channel.send(`Playing: ${song.tracks[0].info.title}`)
- }else {
- msg.channel.send(`Added: ${song.tracks[0].info.title}`)
- }
- }).catch(err => {
- return msg.reply("No songs were found");
- })
- }
- client.on('message', async msg => {
- if(msg.author.bot) return;
- let command = messageArray[0].slice(prefix.length).toLowerCase();
- let args = msg.content.split(" ").splice(1);
- if(!client.queue[msg.guild.id]) {
- client.queue[msg.guild.id] = [];
- }
- if(command === "play") {
- if(!msg.member.voiceChannelID) return msg.reply("You must be in a voice channel");
- if(!msg.member.voiceChannel.joinable) return msg.reply("I don't have the permissions to join your voice channel");
- var queue = client.queue[msg.guild.id] || [];
- const player = client.manager.get(msg.guild.id);
- if(!player) {
- if(client.queue[msg.guild.id][0]) {
- if(!args.join(" ")) return play(client, msg);
- }
- }
- if(args.join(" ").startsWith("http")) {
- getSong(`${args.join(" ")}`, msg);
- }else {
- getSong(`ytsearch:${args.join(" ")}`, msg);
- }
- }
- if(command === "pause") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- if(player.paused === true) return msg.channel.send("Music is already paused");
- player.pause(true);
- msg.channel.send("Music has been paused")
- }
- if(command === "resume") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- if(player.paused === false) return msg.channel.send("Music is already playing");
- player.pause(false);
- msg.channel.send("Music has been resumed");
- }
- if(command === "stop") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- client.queue[msg.guild.id].shift();
- client.manager.leave(msg.guild.id);
- msg.reply("Left voice call");
- }
- if(command === "skip") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- player.stop();
- msg.reply("Song skipped");
- }
- if(command === "seek") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- if(!args[0]) return msg.reply("You must provide a amount of time");
- if(!Number(args[0])) return msg.reply("Amount must be a number");
- player.seek(args[0] * 1000);
- msg.reply(`Successfully skipped to ${args[0]}`);
- }
- if(command === "bassboost") {
- const player = client.manager.get(msg.guild.id);
- if(!player) return msg.reply(language.noMusicPlaying);
- if(!args[0]) return msg.reply("You must provide a amount between 0 and 1");
- if(!Number(args[0])) return msg.reply("Amount must be a number");
- client.manager.get(msg.guild.id).node.send({
- op: "equalizer",
- guildId: msg.guild.id,
- bands: [
- {
- band: args[1] || 0,
- gain: args[0]
- }
- ]
- });
- msg.reply(`Bass boost has been set to ${args[0]}, you should hear the effect soon`);
- }
- if(command === "remove") {
- if(!args[0]) return msg.reply("You must provide a number");
- if(!Number(args[0])) return msg.reply("Value must be a number");
- if(!client.queue[msg.guild.id]) return msg.reply("The queue is empty");
- }
- if(command === "queue") {
- if(client.queue[msg.guild.id].length < 1) return msg.reply("The queue is empty");
- let embed = new Discord.RichEmbed()
- embed.setColor(config.color)
- let queueSize = 0;
- client.queue[msg.guild.id].forEach(song => {
- embed.setFooter(`Total songs ${queueSize}`);
- embed.addField('<a:dbiqueue:496564389638438915> Queue')
- embed.setDescription(`${song.info.title} \`${songinfo.length}\``)
- });
- msg.channel.send(embed)
- }
- if(command === "stats1") {
- console.log(client.manager.get(msg.guild.id).node.stats)
- }
- if(command === "np") {
- msg.channel.send(new Discord.RichEmbed()
- .setColor(config.color)
- .setTitle(client.queue[msg.guild.id][0].info.title)
- .setDescription(`
- Author: ${client.queue[msg.guild.id][0].info.author}
- Duration: ${timeConversion(client.queue[msg.guild.id][0].info.length)}
- `)
- )
- }
- if(command === "eval1") {
- if(msg.author.tag !== "Kaan#8339") return;
- const clean = text => {
- if (typeof(text) === "string")
- return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
- else
- return text;
- }
- try {
- const code = args.join(" ");
- let evaled = eval(code);
- if (typeof evaled !== "string")
- evaled = require("util").inspect(evaled);
- msg.channel.send(clean(evaled), {code:"xl"});
- } catch (err) {
- msg.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
- }
- }
- if(command === "test") {
- return msg.channel.send("```" + JSON.stringify(client.manager.get(msg.guild.id).state) + "```");
- }
- });
- client.login(config.token);
- }
- start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement