Advertisement
Guest User

Untitled

a guest
Feb 15th, 2019
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.95 KB | None | 0 0
  1. const Discord = require('discord.js');
  2. const Lavalink = require('discord.js-lavalink');
  3. const snekfetch = require("snekfetch");
  4. const config = require("./config.js");
  5.  
  6. async function start() {
  7.  
  8. const language = {
  9. noMusicPlaying: "No music is playing!"
  10. }
  11.  
  12. const client = new Discord.Client();
  13.  
  14. client.queue = [];
  15.  
  16. client.on('ready', () => {
  17. client.nodes = [
  18. { host: "localhost", port: 8341, region: "us", password: "0751" }
  19. ];
  20.  
  21. client.manager = new Lavalink.PlayerManager(client, client.nodes, {
  22. user: client.user.id,
  23. shards: 0
  24. });
  25. console.log(`Ready on ${client.guilds.size} guilds`);
  26. });
  27.  
  28. async function getSongs(string) {
  29. const res = await snekfetch.get(`http://${client.nodes[0].host}:${client.nodes[0].port}/loadtracks?identifier=${string}`)
  30. .set("Authorization", client.nodes[0].password)
  31. .catch(err => {
  32. console.error(err);
  33. return null;
  34. });
  35. if (!res) throw "There was an error, try again";
  36. if(!res.body.tracks[0]) return "Error";
  37. console.log(res)
  38. return res.body;
  39. }
  40.  
  41. async function play(client, msg) {
  42. try {
  43. let queue = client.queue[msg.guild.id];
  44. const player = await client.manager.join({
  45. guild: msg.guild.id,
  46. channel: msg.member.voiceChannelID,
  47. host: `${client.nodes[0].host}`
  48. });
  49. console.log(client.queue[msg.guild.id][0]);
  50. player.play(client.queue[msg.guild.id][0].track);
  51. player.once("end", async data => {
  52. queue.shift()
  53. if(client.queue[msg.guild.id][0]) {
  54. setTimeout(() => {
  55. play(client, msg);
  56. msg.channel.send(`Playing: ${client.queue[msg.guild.id][0].info.title}`);
  57. }, 200)
  58. }else {
  59. msg.channel.send("Queue is empty");
  60. await client.manager.leave(msg.guild.id);
  61. }
  62. });
  63. console.log(queue)
  64. }catch(err) {
  65. console.log(err);
  66. }
  67. }
  68.  
  69. async function getSong(string, msg) {
  70. getSongs(string).then(async song => {
  71. if(!song) return msg.reply("No tracks were found");
  72. client.queue[msg.guild.id].push(song.tracks[0]);
  73. const player = client.manager.get(msg.guild.id);
  74. if(!player) {
  75. play(client, msg);
  76. msg.channel.send(`Playing: ${song.tracks[0].info.title}`)
  77. }else {
  78. msg.channel.send(`Added: ${song.tracks[0].info.title}`)
  79. }
  80. }).catch(err => {
  81. return msg.reply("No songs were found");
  82. })
  83. }
  84.  
  85. client.on('message', async msg => {
  86. if(msg.author.bot) return;
  87.  
  88. let command = messageArray[0].slice(prefix.length).toLowerCase();
  89. let args = msg.content.split(" ").splice(1);
  90.  
  91. if(!client.queue[msg.guild.id]) {
  92. client.queue[msg.guild.id] = [];
  93. }
  94.  
  95. if(command === "play") {
  96. if(!msg.member.voiceChannelID) return msg.reply("You must be in a voice channel");
  97. if(!msg.member.voiceChannel.joinable) return msg.reply("I don't have the permissions to join your voice channel");
  98. var queue = client.queue[msg.guild.id] || [];
  99. const player = client.manager.get(msg.guild.id);
  100. if(!player) {
  101. if(client.queue[msg.guild.id][0]) {
  102. if(!args.join(" ")) return play(client, msg);
  103. }
  104. }
  105. if(args.join(" ").startsWith("http")) {
  106. getSong(`${args.join(" ")}`, msg);
  107. }else {
  108. getSong(`ytsearch:${args.join(" ")}`, msg);
  109. }
  110. }
  111.  
  112. if(command === "pause") {
  113. const player = client.manager.get(msg.guild.id);
  114. if(!player) return msg.reply(language.noMusicPlaying);
  115. if(player.paused === true) return msg.channel.send("Music is already paused");
  116.  
  117. player.pause(true);
  118. msg.channel.send("Music has been paused")
  119. }
  120.  
  121. if(command === "resume") {
  122. const player = client.manager.get(msg.guild.id);
  123. if(!player) return msg.reply(language.noMusicPlaying);
  124. if(player.paused === false) return msg.channel.send("Music is already playing");
  125.  
  126. player.pause(false);
  127. msg.channel.send("Music has been resumed");
  128. }
  129.  
  130. if(command === "stop") {
  131. const player = client.manager.get(msg.guild.id);
  132. if(!player) return msg.reply(language.noMusicPlaying);
  133.  
  134. client.queue[msg.guild.id].shift();
  135.  
  136. client.manager.leave(msg.guild.id);
  137. msg.reply("Left voice call");
  138. }
  139.  
  140. if(command === "skip") {
  141. const player = client.manager.get(msg.guild.id);
  142. if(!player) return msg.reply(language.noMusicPlaying);
  143.  
  144. player.stop();
  145.  
  146. msg.reply("Song skipped");
  147. }
  148.  
  149. if(command === "seek") {
  150. const player = client.manager.get(msg.guild.id);
  151. if(!player) return msg.reply(language.noMusicPlaying);
  152. if(!args[0]) return msg.reply("You must provide a amount of time");
  153. if(!Number(args[0])) return msg.reply("Amount must be a number");
  154. player.seek(args[0] * 1000);
  155. msg.reply(`Successfully skipped to ${args[0]}`);
  156. }
  157.  
  158. if(command === "bassboost") {
  159. const player = client.manager.get(msg.guild.id);
  160. if(!player) return msg.reply(language.noMusicPlaying);
  161. if(!args[0]) return msg.reply("You must provide a amount between 0 and 1");
  162. if(!Number(args[0])) return msg.reply("Amount must be a number");
  163. client.manager.get(msg.guild.id).node.send({
  164. op: "equalizer",
  165. guildId: msg.guild.id,
  166. bands: [
  167. {
  168. band: args[1] || 0,
  169. gain: args[0]
  170. }
  171. ]
  172. });
  173. msg.reply(`Bass boost has been set to ${args[0]}, you should hear the effect soon`);
  174. }
  175.  
  176. if(command === "remove") {
  177. if(!args[0]) return msg.reply("You must provide a number");
  178. if(!Number(args[0])) return msg.reply("Value must be a number");
  179. if(!client.queue[msg.guild.id]) return msg.reply("The queue is empty");
  180. }
  181.  
  182. if(command === "queue") {
  183. if(client.queue[msg.guild.id].length < 1) return msg.reply("The queue is empty");
  184. let embed = new Discord.RichEmbed()
  185. embed.setColor(config.color)
  186. let queueSize = 0;
  187. client.queue[msg.guild.id].forEach(song => {
  188. embed.setFooter(`Total songs ${queueSize}`);
  189. embed.addField('<a:dbiqueue:496564389638438915> Queue')
  190. embed.setDescription(`${song.info.title} \`${songinfo.length}\``)
  191. });
  192.  
  193. msg.channel.send(embed)
  194. }
  195.  
  196. if(command === "stats1") {
  197. console.log(client.manager.get(msg.guild.id).node.stats)
  198. }
  199.  
  200. if(command === "np") {
  201. msg.channel.send(new Discord.RichEmbed()
  202. .setColor(config.color)
  203. .setTitle(client.queue[msg.guild.id][0].info.title)
  204. .setDescription(`
  205. Author: ${client.queue[msg.guild.id][0].info.author}
  206. Duration: ${timeConversion(client.queue[msg.guild.id][0].info.length)}
  207. `)
  208. )
  209. }
  210.  
  211. if(command === "eval1") {
  212. if(msg.author.tag !== "Kaan#8339") return;
  213. const clean = text => {
  214. if (typeof(text) === "string")
  215. return text.replace(/`/g, "`" + String.fromCharCode(8203)).replace(/@/g, "@" + String.fromCharCode(8203));
  216. else
  217. return text;
  218. }
  219. try {
  220. const code = args.join(" ");
  221. let evaled = eval(code);
  222.  
  223. if (typeof evaled !== "string")
  224. evaled = require("util").inspect(evaled);
  225.  
  226. msg.channel.send(clean(evaled), {code:"xl"});
  227. } catch (err) {
  228. msg.channel.send(`\`ERROR\` \`\`\`xl\n${clean(err)}\n\`\`\``);
  229. }
  230. }
  231.  
  232. if(command === "test") {
  233. return msg.channel.send("```" + JSON.stringify(client.manager.get(msg.guild.id).state) + "```");
  234. }
  235. });
  236.  
  237. client.login(config.token);
  238. }
  239.  
  240. start();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement