Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if (message.content.startsWith(`${perfix}play`)) {
- execute(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${perfix}skip`)) {
- skip(message, serverQueue);
- return;
- } else if (message.content.startsWith(`${perfix}stop`)) {
- stop(message, serverQueue);
- return;
- } else {
- return;
- }
- });
- async function execute(message, serverQueue) {
- const args = message.content.split(" ");
- const voiceChannel = message.member.voiceChannel;
- if (!voiceChannel) {
- }
- const permissions = voiceChannel.permissionsFor(message.client.user);
- if (!permissions.has("CONNECT") || !permissions.has("SPEAK")) {
- }
- 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;
- play(message.guild, queueContruct.songs[0]);
- } catch (err) {
- console.log(err);
- queue.delete(message.guild.id);
- return message.channel.send(err);
- }
- } else {
- serverQueue.songs.push(song);
- console.log(serverQueue.songs);
- }
- }
- async function skip(message, serverQueue) {
- if (!message.member.voiceChannel) {
- }
- if (!serverQueue) {
- }
- serverQueue.connection.dispatcher.end();
- }
- async function stop(message, serverQueue) {
- if (!message.member.voiceChannel) {
- }
- serverQueue.songs = [];
- serverQueue.connection.dispatcher.end();
- }
- function play(guild, song) {
- const serverQueue = queue.get(guild.id);
- if (!song) {
- serverQueue.voiceChannel.leave();
- queue.delete(guild.id);
- return;
- }
- const dispatcher = serverQueue.connection
- .playStream(ytdl(song.url))
- .on("end", () => {
- console.log("Music ended!");
- serverQueue.songs.shift();
- play(guild, serverQueue.songs[0]);
- })
- .on("error", error => {
- console.error(error);
- });
- dispatcher.setVolumeLogarithmic(serverQueue.volume / 5);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement