Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const Discord = require("discord.js");
- const ytsearch = require("yt-search");
- const ffmpeg = require("ffmpeg");
- const ytdl = require("ytdl-core");
- const config = require("../config.json");
- module.exports.run = async (bot, message, args, opts) => {
- if(!message.member.voiceChannel) return message.channel.send("You must be connected to a voice chat to run this command.");
- if(message.guild.me.voiceChannel) return message.channel.send("I am already connected to a voice chat!");
- if(!args[0]) return message.channel.send("Please provide a URL.");
- let valid = await ytdl.validateURL(args[0]);
- if(!valid) return message.channel.send("Please provide a valid URL.");
- let info = await ytdl.getInfo(args[0]);
- let connect = await message.member.voiceChannel.join();
- let dp = await connect.playStream(ytdl(args[0], {filter: 'audio' }));
- message.channel.send(`🎵 Now Playing: ${info.title}`);
- let data = opts.active.get(message.guild.id) || {};
- if(!data.connect) data.connect = await message.member.voiceChannel.join();
- if(!data.queue) data.queue = [];
- data.guildID = message.guild.id;
- data.queue.push({
- songTitle: info.title,
- requestedBy: message.author.tag,
- url: args[0],
- announcementChannel: message.channel.id
- });
- if(!data.dp) play(bot, opts, data);
- else {
- message.channel.send(`Added To Queue: ${info.title} | Requested By: ${message.author.id}`);
- }
- opts.active.set(message.guild.id, data);
- };
- async function play(bot, opts, data) {
- bot.channels.get(data.queue[0].announcementChannel).send(`🎵 Now Playing: ${data.queue[0]} | Requested By: ${data.queue[0].requestedBy}`);
- data.dp = await data.connect.playStream(ytdl(data.queue[0].url, { filter: 'audio' }));
- data.dp.guildID = data.guildID;
- data.dp.once('finish', function() {
- finish(bot, opts, data)
- });
- }
- function end(bot, opts, dp) {
- let fetched = opts.active.get(dp.guildID)
- fetched.queue.shift()
- if(fetched.queue.length > 0) {
- opts.active.set(dp.guildID, fetched);
- play(bot, opts, fetched)
- } else {
- opts.active.delete(dp.guildID)
- let vc = bot.guilds.get(dp.guildID).me.voiceChannel
- if(vc) vc = vc.leave()
- }
- }
- module.exports.help = {
- name: "play",
- aliases: ["p"]
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement