NevaehAnimeLover

Untitled

Jan 21st, 2021
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.11 KB | None | 0 0
  1. const { log } = require('console');
  2. const Discord = require('discord.js')
  3. const youtube_sr = require("youtube-sr");
  4. const ytdl = require("ytdl-core")
  5. const client = new Discord.Client()
  6. const prefix = '^';
  7. const none = ""
  8. client.on('message', message => {
  9. const queue = new Map();
  10. const serverQueue = queue.get(message.guild.id);
  11. var args = message.content.substring(prefix.length).split(" ");
  12. if (message.content.startsWith(prefix + "play")) {
  13. if (message.member.voice.channel) {
  14. const connection = message.member.voice.channel.join();
  15. const query = args.join(" ");
  16. const errorQuery = new Discord.MessageEmbed()
  17. .setTitle('Hmmm')
  18. .setDescription('Uh oh! Seems like you did not provide a search query!')
  19. .setColor('#f90000')
  20. .setFooter('Usage: p!ytplay Rick Roll')
  21. if (!query) return message.channel.send(errorQuery);
  22. const res = youtube_sr.search(query).catch(e => {
  23. const errorNoResult = new Discord.MessageEmbed()
  24. .setTitle('Hmmm')
  25. .setDescription('Oh no! I cannot find any results on YouTube! Try a different search query.')
  26. .setColor('#f90000')
  27. return message.channel.send(errorNoResult)
  28. });
  29. const video = res[0]
  30.  
  31.  
  32. function convert(duration) {
  33. var milliseconds = parseInt((duration % 1000) / 100),
  34. seconds = Math.floor((duration / 1000) % 60),
  35. minutes = Math.floor((duration / (1000 * 60)) % 60),
  36. hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
  37.  
  38. hours = (hours < 10) ? "0" + hours : hours;
  39. minutes = (minutes < 10) ? "0" + minutes : minutes;
  40. seconds = (seconds < 10) ? "0" + seconds : seconds;
  41.  
  42. return (hours == "00" ? "" : hours + " hrs ") + (minutes == "00" ? "" : minutes + " mins ") + seconds + " secs";
  43. }
  44. connection.play(ytdl(video.url, { quality: 'highestaudio'}));
  45.  
  46. const nowplaying = new Discord.MessageEmbed()
  47. .setTitle(`Now playing ${video.title}`)
  48. .setImage(video.thumbnail.url)
  49. .setColor('#f90000')
  50. .addField("Views", video.views.toLocaleString(), true)
  51. .setURL(video.url)
  52. .setDescription(video.url)
  53. .addField("Duration", convert(video.duration), true)
  54. return message.channel.send(nowplaying)
  55.  
  56. }
  57.  
  58. else{
  59. const vcErrorEmbed = new Discord.MessageEmbed()
  60. .setTitle('Hmmm')
  61. .setDescription('Cutie pls join a voice channel')
  62. .setColor('Green')
  63. .setFooter('Music!')
  64. message.channel.send(vcErrorEmbed)
  65. }
  66. }
  67. })
  68.  
Advertisement
Add Comment
Please, Sign In to add comment