Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { log } = require('console');
- const Discord = require('discord.js')
- const youtube_sr = require("youtube-sr");
- const ytdl = require("ytdl-core")
- const client = new Discord.Client()
- const prefix = '^';
- const none = ""
- client.on('message', message => {
- const queue = new Map();
- const serverQueue = queue.get(message.guild.id);
- var args = message.content.substring(prefix.length).split(" ");
- if (message.content.startsWith(prefix + "play")) {
- if (message.member.voice.channel) {
- const connection = message.member.voice.channel.join();
- const query = args.join(" ");
- const errorQuery = new Discord.MessageEmbed()
- .setTitle('Hmmm')
- .setDescription('Uh oh! Seems like you did not provide a search query!')
- .setColor('#f90000')
- .setFooter('Usage: p!ytplay Rick Roll')
- if (!query) return message.channel.send(errorQuery);
- const res = youtube_sr.search(query).catch(e => {
- const errorNoResult = new Discord.MessageEmbed()
- .setTitle('Hmmm')
- .setDescription('Oh no! I cannot find any results on YouTube! Try a different search query.')
- .setColor('#f90000')
- return message.channel.send(errorNoResult)
- });
- const video = res[0]
- function convert(duration) {
- var milliseconds = parseInt((duration % 1000) / 100),
- seconds = Math.floor((duration / 1000) % 60),
- minutes = Math.floor((duration / (1000 * 60)) % 60),
- hours = Math.floor((duration / (1000 * 60 * 60)) % 24);
- hours = (hours < 10) ? "0" + hours : hours;
- minutes = (minutes < 10) ? "0" + minutes : minutes;
- seconds = (seconds < 10) ? "0" + seconds : seconds;
- return (hours == "00" ? "" : hours + " hrs ") + (minutes == "00" ? "" : minutes + " mins ") + seconds + " secs";
- }
- connection.play(ytdl(video.url, { quality: 'highestaudio'}));
- const nowplaying = new Discord.MessageEmbed()
- .setTitle(`Now playing ${video.title}`)
- .setImage(video.thumbnail.url)
- .setColor('#f90000')
- .addField("Views", video.views.toLocaleString(), true)
- .setURL(video.url)
- .setDescription(video.url)
- .addField("Duration", convert(video.duration), true)
- return message.channel.send(nowplaying)
- }
- else{
- const vcErrorEmbed = new Discord.MessageEmbed()
- .setTitle('Hmmm')
- .setDescription('Cutie pls join a voice channel')
- .setColor('Green')
- .setFooter('Music!')
- message.channel.send(vcErrorEmbed)
- }
- }
- })
Advertisement
Add Comment
Please, Sign In to add comment