JaBa/commands/Owner/servers-list.js

124 lines
3.6 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 ServersList extends Command {
2021-12-26 19:29:37 +05:00
constructor(client) {
2021-12-10 21:39:54 +05:00
super(client, {
name: "servers-list",
dirname: __dirname,
enabled: true,
guildOnly: false,
2021-12-26 19:29:37 +05:00
aliases: ["slist"],
2021-12-10 21:39:54 +05:00
memberPermissions: [],
2021-12-26 19:29:37 +05:00
botPermissions: ["SEND_MESSAGES", "EMBED_LINKS"],
2021-12-10 21:39:54 +05:00
nsfw: false,
ownerOnly: true,
cooldown: 3000
2021-12-10 21:39:54 +05:00
});
}
2021-12-26 19:29:37 +05:00
async run(message, args, data) {
2022-01-04 01:13:38 +05:00
if (!message.channel.type !== "DM") message.delete();
2021-12-10 21:39:54 +05:00
2021-12-26 19:29:37 +05:00
let i0 = 0,
i1 = 10,
page = 1;
2021-12-10 21:39:54 +05:00
2021-12-11 01:11:50 +05:00
let description = `${message.translate("common:SERVERS")}: ${this.client.guilds.cache.size}\n\n` +
2021-12-26 19:29:37 +05:00
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
2021-12-10 21:39:54 +05:00
.map((r, i) => `**${i + 1}** - ${r.name} | ${r.memberCount} ${message.translate("common:MEMBERS").toLowerCase()}`)
.slice(0, 10)
.join("\n");
const embed = new Discord.MessageEmbed()
2022-01-04 00:35:11 +05:00
.setAuthor({
name: message.author.tag,
iconURL: message.author.displayAvatarURL({
size: 512,
dynamic: true,
format: "png"
})
})
2021-12-10 21:39:54 +05:00
.setColor(data.config.embed.color)
2022-01-04 00:35:11 +05:00
.setFooter({
text: this.client.user.username
})
2021-12-10 21:39:54 +05:00
.setTitle(`${message.translate("common:PAGE")}: ${page}/${Math.ceil(this.client.guilds.cache.size/10)}`)
.setDescription(description);
2022-01-04 00:35:11 +05:00
const msg = await message.channel.send({
embeds: [embed]
});
2021-12-11 01:11:50 +05:00
2021-12-10 21:39:54 +05:00
await msg.react("⬅");
await msg.react("➡");
await msg.react("❌");
2022-01-03 23:20:33 +05:00
const filter = (reaction, user) => user.id === message.author.id;
2022-01-04 00:35:11 +05:00
const collector = msg.createReactionCollector({
filter,
2022-01-03 23:20:33 +05:00
time: 30000
});
2021-12-10 21:39:54 +05:00
2021-12-26 19:29:37 +05:00
collector.on("collect", async (reaction) => {
2021-12-11 01:11:50 +05:00
if (reaction._emoji.name === "⬅") {
2021-12-10 21:39:54 +05:00
// Updates variables
2021-12-11 01:11:50 +05:00
i0 = i0 - 10;
i1 = i1 - 10;
page = page - 1;
2021-12-10 21:39:54 +05:00
// if there is no guild to display, delete the message
2021-12-11 01:11:50 +05:00
if (i0 < 0) return msg.delete();
if (!i0 || !i1) return msg.delete();
description = `${message.translate("common:SERVERS")}: ${this.client.guilds.cache.size}\n\n` +
2021-12-26 19:29:37 +05:00
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
2021-12-10 21:39:54 +05:00
.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);
2021-12-11 01:11:50 +05:00
// Edit the message
2022-01-04 00:35:11 +05:00
msg.edit({
embeds: [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
if (reaction._emoji.name === "➡") {
2021-12-10 21:39:54 +05:00
// Updates variables
2021-12-11 01:11:50 +05:00
i0 = i0 + 10;
i1 = i1 + 10;
page = page + 1;
2021-12-10 21:39:54 +05:00
// if there is no guild to display, delete the message
2021-12-11 01:11:50 +05:00
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` +
2021-12-26 19:29:37 +05:00
this.client.guilds.cache.sort((a, b) => b.memberCount - a.memberCount).map((r) => r)
2021-12-10 21:39:54 +05:00
.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);
2021-12-11 01:11:50 +05:00
// Edit the message
2022-01-04 00:35:11 +05:00
msg.edit({
embeds: [embed]
});
2021-12-11 01:11:50 +05:00
};
2021-12-10 21:39:54 +05:00
2022-01-04 01:13:38 +05:00
if (reaction._emoji.name === "❌" && !message.channel.type !== "DM") return msg.delete();
2021-12-10 21:39:54 +05:00
// Remove the reaction when the user react to the message
await reaction.users.remove(message.author.id);
});
}
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 = ServersList;