mirror of
https://github.com/JonnyBro/JaBa.git
synced 2024-11-23 05:34:58 +05:00
109 lines
No EOL
3.4 KiB
JavaScript
109 lines
No EOL
3.4 KiB
JavaScript
const Command = require("../../base/Command.js"),
|
|
Discord = require("discord.js");
|
|
|
|
class ServersList extends Command {
|
|
constructor(client) {
|
|
super(client, {
|
|
name: "servers-list",
|
|
dirname: __dirname,
|
|
enabled: true,
|
|
guildOnly: false,
|
|
aliases: ["slist"],
|
|
memberPermissions: [],
|
|
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
|
|
nsfw: false,
|
|
ownerOnly: true,
|
|
cooldown: 3000
|
|
});
|
|
}
|
|
|
|
async run(message, args, data) {
|
|
if (!message.channel.type != "dm") message.delete();
|
|
|
|
let i0 = 0,
|
|
i1 = 10,
|
|
page = 1;
|
|
|
|
let description = `${message.translate("common:SERVERS")}: ${this.client.guilds.cache.size}\n\n` +
|
|
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS").toLowerCase()}`)
|
|
.slice(0, 10)
|
|
.join("\n");
|
|
|
|
const embed = new Discord.MessageEmbed()
|
|
.setAuthor(message.author.tag, message.author.displayAvatarURL({
|
|
size: 512,
|
|
dynamic: true,
|
|
format: "png"
|
|
}))
|
|
.setColor(data.config.embed.color)
|
|
.setFooter(this.client.user.username)
|
|
.setTitle(`${message.translate("common:PAGE")}: ${page}/${Math.ceil(this.client.guilds.cache.size/10)}`)
|
|
.setDescription(description);
|
|
|
|
const msg = await message.channel.send(embed);
|
|
|
|
await msg.react("⬅");
|
|
await msg.react("➡");
|
|
await msg.react("❌");
|
|
|
|
const collector = msg.createReactionCollector((reaction, user) => user.id === message.author.id);
|
|
|
|
collector.on("collect", async (reaction) => {
|
|
if (reaction._emoji.name === "⬅") {
|
|
// Updates variables
|
|
i0 = i0 - 10;
|
|
i1 = i1 - 10;
|
|
page = page - 1;
|
|
|
|
// if there is no guild to display, delete the message
|
|
if (i0 < 0) return msg.delete();
|
|
if (!i0 || !i1) return msg.delete();
|
|
|
|
description = `${message.translate("common:SERVERS")}: ${this.client.guilds.cache.size}\n\n` +
|
|
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS")}`)
|
|
.slice(i0, i1)
|
|
.join("\n");
|
|
|
|
// Update the embed with new informations
|
|
embed.setTitle(`${message.translate("common:PAGE")}: ${page}/${Math.round(this.client.guilds.cache.size/10)}`)
|
|
.setDescription(description);
|
|
|
|
// Edit the message
|
|
msg.edit(embed);
|
|
};
|
|
|
|
if (reaction._emoji.name === "➡") {
|
|
// Updates variables
|
|
i0 = i0 + 10;
|
|
i1 = i1 + 10;
|
|
page = page + 1;
|
|
|
|
// if there is no guild to display, delete the message
|
|
if (i1 > this.client.guilds.cache.size + 10) return msg.delete();
|
|
if (!i0 || !i1) return msg.delete();
|
|
|
|
description = `${message.translate("common:SERVERS")}: ${this.client.guilds.cache.size}\n\n` +
|
|
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS").toLowerCase()}`)
|
|
.slice(i0, i1)
|
|
.join("\n");
|
|
|
|
// Update the embed with new informations
|
|
embed.setTitle(`${message.translate("common:PAGE")}: ${page}/${Math.round(this.client.guilds.cache.size/10)}`)
|
|
.setDescription(description);
|
|
|
|
// Edit the message
|
|
msg.edit(embed);
|
|
};
|
|
|
|
if (reaction._emoji.name === "❌") return msg.delete();
|
|
|
|
// Remove the reaction when the user react to the message
|
|
await reaction.users.remove(message.author.id);
|
|
});
|
|
}
|
|
};
|
|
|
|
module.exports = ServersList; |