2022-01-13 00:56:24 +05:00
|
|
|
const Command = require("../../base/Command"),
|
2022-01-04 02:18:28 +05:00
|
|
|
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) {
|
2022-01-27 20:22:12 +05:00
|
|
|
if (message.channel.type !== "DM") message.delete();
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
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)
|
2022-01-13 00:26:23 +05:00
|
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS").toLowerCase()}`)
|
|
|
|
.slice(0, 10)
|
|
|
|
.join("\n");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
const embed = new Discord.MessageEmbed()
|
2022-01-05 00:24:57 +05:00
|
|
|
.setAuthor({
|
|
|
|
name: message.author.tag,
|
|
|
|
iconURL: message.author.displayAvatarURL({
|
|
|
|
size: 512,
|
|
|
|
dynamic: true,
|
|
|
|
format: "png"
|
|
|
|
})
|
|
|
|
})
|
2022-01-04 02:18:28 +05:00
|
|
|
.setColor(data.config.embed.color)
|
2022-01-05 00:24:57 +05:00
|
|
|
.setFooter({
|
|
|
|
text: this.client.user.username
|
|
|
|
})
|
2022-01-04 02:18:28 +05:00
|
|
|
.setTitle(`${message.translate("common:PAGE")}: ${page}/${Math.ceil(this.client.guilds.cache.size/10)}`)
|
|
|
|
.setDescription(description);
|
|
|
|
|
2022-02-13 17:26:12 +05:00
|
|
|
const msg = await message.reply({
|
2022-01-05 00:24:57 +05:00
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
await msg.react("⬅");
|
|
|
|
await msg.react("➡");
|
|
|
|
await msg.react("❌");
|
|
|
|
|
2022-01-05 00:24:57 +05:00
|
|
|
const filter = (reaction, user) => user.id === message.author.id;
|
|
|
|
const collector = msg.createReactionCollector({
|
|
|
|
filter,
|
|
|
|
time: 30000
|
|
|
|
});
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
collector.on("collect", async (reaction) => {
|
2022-02-19 21:11:14 +05:00
|
|
|
if (message.channel.type === "DM") return;
|
|
|
|
|
|
|
|
if (reaction._emoji.name === "⬅") {
|
2022-01-04 02:18:28 +05:00
|
|
|
// 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)
|
2022-01-13 00:26:23 +05:00
|
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS")}`)
|
|
|
|
.slice(i0, i1)
|
|
|
|
.join("\n");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// 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
|
2022-01-05 00:24:57 +05:00
|
|
|
msg.edit({
|
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-02-19 21:11:14 +05:00
|
|
|
if (reaction._emoji.name === "➡") {
|
2022-01-04 02:18:28 +05:00
|
|
|
// 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)
|
2022-01-13 00:26:23 +05:00
|
|
|
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS").toLowerCase()}`)
|
|
|
|
.slice(i0, i1)
|
|
|
|
.join("\n");
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// 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
|
2022-01-05 00:24:57 +05:00
|
|
|
msg.edit({
|
|
|
|
embeds: [embed]
|
|
|
|
});
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
2022-02-19 21:11:14 +05:00
|
|
|
if (reaction._emoji.name === "❌") return msg.delete();
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
// Remove the reaction when the user react to the message
|
|
|
|
await reaction.users.remove(message.author.id);
|
|
|
|
});
|
|
|
|
}
|
2022-01-13 00:26:23 +05:00
|
|
|
}
|
2022-01-04 02:18:28 +05:00
|
|
|
|
|
|
|
module.exports = ServersList;
|