Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const ytdl = require("ytdl-core");
- const Discord = require('discord.js');
- exports.run = async (client, message, args) => {
- const link = message.content.split(" ");
- const queue = message.client.queue;
- const serverQueue = message.client.queue.get(message.channel.guild.id)
- const voiceChannel = message.member.voiceChannel;
- if (!voiceChannel)
- return message.channel.send("**Entre em um canal de voz. Depois é só me chamar!**");
- const permissions = voiceChannel.permissionsFor(message.client.user);
- if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
- return message.channel.send("**Eu não tenho permissão pra soltar a música!**");
- }
- const songInfo = await ytdl.getInfo(args[1]);
- const song = {
- title: songInfo.title,
- url: songInfo.video_url
- };
- if (!serverQueue) {
- const queueContruct = {
- textChannel: message.channel,
- voiceChannel: voiceChannel,
- connection: null,
- songs: [],
- volume: 5,
- playing: true
- }
- queue.set(message.guild.id, queueContruct);
- queueContruct.songs.push(song);
- try {
- var connection = await voiceChannel.join();
- queueContruct.connection = connection;
- this.play(message, queueContruct.songs[0]);
- message.channel.send(`Estou tocando: ${song.title}`)
- } catch (err) {
- console.log(err);
- queue.delete(message.guild.id);
- return message.channel.send(err);
- } else {
- serverQueue.songs.push(song);
- return message.channel.send(`**${song.title} foi adicionada a playlist!**`);
- }
- } catch (error) {
- message.channel.send("**Apenas link's do youtube serão aceitos**");
- }
- }
- play(message, song)
- const queue = message.client.queue;
- const guild = message.guild;
- const serverQueue = queue.get(message.guild.id);
- const dispatcher = serverQueue.connection
- .playStream(ytdl(song.url, { fliter: "audioonly" }))
- .on("end", () => {
- message.channel.send('**Acabou a música!** 🔴');
- serverQueue.songs.shift();
- this.play(message, serverQueue.songs[0]);
- })
- .on("error", error => {
- console.error(error);
- });
- dispatcher.setVolumeLogarithmic(serverQueue.volume / 10);
- exports.help = {
- name: 'play'
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement