Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const { Client, Util } = require('discord.js');
- const Discord = require("discord.js");
- const YouTube = require('simple-youtube-api');
- const ytdl = require('ytdl-core');
- const FFMPEG = require('ffmpeg');
- const client = new Client({ disableEveryone: true });
- const youtube = new YouTube("AIzaSyAdORXg7UZUo7sePv97JyoDqtQVi3Ll0b8");
- const queue = new Map();
- const PREFIX = '$'
- client.on('ready', () => {
- console.log('Logging into Discord..');
- console.log(`I'm Ready Now`);
- });
- client.on('warn', console.warn);
- client.on('error', console.error);
- client.on('disconnect', () => console.log('I just disconnected, making sure you know, I will reconnect now...'));
- client.on('reconnecting', () => console.log('I am reconnecting now!'));
- /*
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- ////////////////////////\\\\\\\\\\\\\\\\\\\\\\\\\
- */
- var servers = [];
- var guilds = [];
- var queueNames = [];
- var isPlaying = false;
- var dispatcher = null;
- var voiceChannel = null;
- var skipReq = 0;
- var skippers = [];
- var now_playing = [];
- /*
- \\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////
- \\\\\\\\\\\\\\\\\\\\\\\\/////////////////////////
- */
- client.on('message', async msg => { // eslint-disable-line
- if (msg.author.bot) return undefined;
- if (!msg.content.startsWith(PREFIX)) return undefined;
- const args = msg.content.split(' ');
- const searchString = args.slice(1).join(' ');
- const url = args[1] ? args[1].replace(/<(.+)>/g, '$1') : '';
- const serverQueue = queue.get(msg.guild.id);
- let command = msg.content.toLowerCase().split(" ")[0];
- command = command.slice(PREFIX.length)
- if (command === `play`) {
- const voiceChannel = msg.member.voiceChannel;
- if (!voiceChannel) return msg.channel.send('You must join a voice channel first.');
- if (url.match(/^https?:\/\/(www.youtube.com|youtube.com)\/playlist(.*)$/)) {
- const playlist = await youtube.getPlaylist(url);
- const videos = await playlist.getVideos();
- for (const video of Object.values(videos)) {
- const video2 = await youtube.getVideoByID(video.id); // eslint-disable-line no-await-in-loop
- await handleVideo(video2, msg, voiceChannel, true); // eslint-disable-line no-await-in-loop
- }
- return msg.channel.send(` **${playlist.title}** تم اضافة القائمه!`);
- } else {
- try {
- var video = await youtube.getVideo(url);
- } catch (error) {
- try {
- var videos = await youtube.searchVideos(searchString, 5);
- let index = 0;
- const embed1 = new Discord.RichEmbed()
- .setAuthor(`Music`, `https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- .setDescription(`**Please select a track with the 1-5 **
- ${videos.map(video2 => `[**${++index} **] \`${video2.title}\``).join('\n')}`)
- .setFooter(`Music`,`https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- msg.channel.sendEmbed(embed1).then(message =>{message.delete(10000)})
- // eslint-disable-next-line max-depth
- try {
- var response = await msg.channel.awaitMessages(msg2 => msg2.content > 0 && msg2.content < 11, {
- maxMatches: 1,
- time: 10000,
- errors: ['time']
- });
- } catch (err) {
- console.error(err);
- return msg.channel.send('Time Out Please try again.');
- }
- const videoIndex = parseInt(response.first().content);
- var video = await youtube.getVideoByID(videos[videoIndex - 1].id);
- } catch (err) {
- console.error(err);
- return msg.channel.send('I could not get any search results.');
- }
- }
- return handleVideo(video, msg, voiceChannel);
- }
- } else if (command === `skip`) {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing that I could skip for you.');
- serverQueue.connection.dispatcher.connectoin('Skip command has been used!');
- return undefined;
- } else if (command === `stop`) {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing that I could stop for you.');
- serverQueue.songs = [];
- serverQueue.connection.dispatcher.end('Stop command has been used!');
- return undefined;
- } else if (command === `vol`) {
- if (!msg.member.voiceChannel) return msg.channel.send('You are not in a voice channel!');
- if (!serverQueue) return msg.channel.send('There is nothing playing.');
- if (!args[1]) return msg.channel.send(`:loud_sound: Current volume is **${serverQueue.volume}**`);
- serverQueue.volume = args[1];
- serverQueue.connection.dispatcher.setVolumeLogarithmic(args[1] / 5);
- return msg.channel.send(`:speaker: تم تغير الصوت الي **${args[1]}**`);
- } else if (command === `np`) {
- if (!serverQueue) return msg.channel.send('nothing playing now.');
- const embedNP = new Discord.RichEmbed()
- .setAuthor(`Music`, `https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- .setDescription(`**Now Playing :** **${serverQueue.songs[0].title}**`)
- .setFooter(`Music`,`https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- return msg.channel.sendEmbed(embedNP);
- } else if (command === `list`) {
- if (!serverQueue) return msg.channel.send('There is nothing playing.');
- let index = 0;
- const embedqu = new Discord.RichEmbed()
- .setAuthor(`Music`, `https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- .setDescription(`**List Music**
- ${serverQueue.songs.map(song => `**${++index} -** ${song.title}`).join('\n')}
- **Now Playing :** ${serverQueue.songs[0].title}`)
- .setFooter(`Music`,`https://cdn.discordapp.com/attachments/404998213347704852/413782918368985109/53ba3a8530c9f645c09e1a49eb3421b2--s-star-design-branding.jpg`)
- return msg.channel.sendEmbed(embedqu);
- } else if (command === `pause`) {
- if (serverQueue && serverQueue.playing) {
- serverQueue.playing = false;
- serverQueue.connection.dispatcher.pause();
- return msg.channel.send('Music paused!');
- }
- return msg.channel.send('There is nothing playing.');
- } else if (command === `resume`) {
- if (serverQueue && !serverQueue.playing) {
- serverQueue.playing = true;
- serverQueue.connection.dispatcher.resume();
- return msg.channel.send('Music resumed.');
- }
- return msg.channel.send('nothing playing now.');
- }
- return undefined;
- });
- async function handleVideo(video, msg, voiceChannel, playlist = false) {
- const serverQueue = queue.get(msg.guild.id);
- console.log(video);
- const song = {
- id: video.id,
- title: Util.escapeMarkdown(video.title),
- url: `https://www.youtube.com/watch?v=${video.id}`
- };
- if (!serverQueue) {
- const queueConstruct = {
- textChannel: msg.channel,
- voiceChannel: voiceChannel,
- connection: null,
- songs: [],
- volume: 5,
- playing: true
- };
- queue.set(msg.guild.id, queueConstruct);
- queueConstruct.songs.push(song);
- try {
- var connection = await voiceChannel.join();
- queueConstruct.connection = connection;
- play(msg.guild, queueConstruct.songs[0]);
- } catch (error) {
- console.error(`I could not join the voice channel: ${error}`);
- queue.delete(msg.guild.id);
- return msg.channel.send(`I could not join the voice channel: ${error}`);
- }
- } else {
- serverQueue.songs.push(song);
- console.log(serverQueue.songs);
- if (playlist) return undefined;
- else return msg.channel.send(`Queued : **${song.title}**`);
- }
- return undefined;
- }
- function play(guild, song) {
- const serverQueue = queue.get(guild.id);
- if (!song) {
- serverQueue.voiceChannel.leave();
- queue.delete(guild.id);
- return;
- }
- console.log(serverQueue.songs);
- const dispatcher = serverQueue.connection.playStream(ytdl(song.url))
- .on('end', reason => {
- if (reason === 'Stream is not generating quickly enough.') console.log('Song ended.');
- else console.log(reason);
- serverQueue.songs.shift();
- play(guild, serverQueue.songs[0]);
- })
- .on('error', error => console.error(error));
- dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
- serverQueue.textChannel.send(`Now playing : **${song.title}**`);
- }
- client.login("Token");
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement