JaBa/commands/Music/back.js

87 lines
2.7 KiB
JavaScript
Raw Normal View History

2021-12-10 21:39:54 +05:00
const Command = require("../../base/Command.js"),
Discord = require("discord.js");
class Back extends Command {
constructor (client) {
super(client, {
name: "back",
dirname: __dirname,
enabled: true,
guildOnly: true,
aliases: [ "previous" ],
memberPermissions: [],
botPermissions: [ "SEND_MESSAGES", "EMBED_LINKS" ],
nsfw: false,
ownerOnly: false,
cooldown: 5000
});
}
async run (message, args, data) {
const queue = this.client.player.getQueue(message);
const voice = message.member.voice.channel;
2021-12-11 01:11:50 +05:00
if (!voice) return message.error("music/play:NO_VOICE_CHANNEL");
if (!queue) return message.error("music/play:NOT_PLAYING");
if (!queue.previousTracks[0]) return message.error("music/back:NO_PREV_SONG");
2021-12-10 21:39:54 +05:00
const members = voice.members.filter((m) => !m.user.bot);
const embed = new Discord.MessageEmbed()
.setAuthor(message.translate("music/back:DESCRIPTION"))
.setThumbnail(queue.tracks[0].thumbnail)
.setFooter(data.config.embed.footer)
.setColor(data.config.embed.color);
const m = await message.channel.send(embed);
2021-12-19 16:45:01 +05:00
if (args[0] && (args[0] === "force" || args[0] === "f")) {
if (message.author.hasPermission("ADMINISTRATOR") || message.author.hasPermission("MANAGE_MESSAGES")) {
this.client.player.back(message);
embed.setDescription(message.translate("music/back:SUCCESS"));
m.edit(embed);
} else message.error("music/back:NO_PERMS");
} else if (members.size > 1) {
2021-12-10 21:39:54 +05:00
m.react("👍");
2021-12-19 16:36:46 +05:00
const mustVote = Math.floor(members.size / 2);
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
embed.setDescription(message.translate("music/back:VOTE_CONTENT", { songName: queue.tracks[0].name, voteCount: 0, requiredCount: mustVote }));
2021-12-10 21:39:54 +05:00
m.edit(embed);
2021-12-11 01:11:50 +05:00
2021-12-10 21:39:54 +05:00
const filter = (reaction, user) => {
const member = message.guild.members.cache.get(user.id);
const voiceChannel = member.voice.channel;
2021-12-11 01:11:50 +05:00
if (voiceChannel) return voiceChannel.id === voice.id;
2021-12-10 21:39:54 +05:00
};
const collector = await m.createReactionCollector(filter, {
time: 25000
});
collector.on("collect", (reaction) => {
2021-12-11 01:11:50 +05:00
const haveVoted = reaction.count - 1;
if (haveVoted >= mustVote) {
2021-12-10 21:39:54 +05:00
this.client.player.back(message);
embed.setDescription(message.translate("music/back:SUCCESS"));
m.edit(embed);
collector.stop(true);
} else {
2021-12-11 01:11:50 +05:00
embed.setDescription(message.translate("music/back:VOTE_CONTENT", { songName: queue.tracks[0].title, voteCount: haveVoted, requiredCount: mustVote }));
2021-12-10 21:39:54 +05:00
m.edit(embed);
}
});
collector.on("end", (collected, isDone) => {
2021-12-11 01:11:50 +05:00
if (!isDone) return message.error("misc:TIMES_UP");
2021-12-10 21:39:54 +05:00
});
} else {
this.client.player.back(message);
embed.setDescription(message.translate("music/back:SUCCESS"));
m.edit(embed);
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
}
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
module.exports = Back;