$getClientGuilds
Returns a list of all guilds of which your bot is a member.
Usage
$getClientGuilds[format?;sort?;order?;list?;page?;sep?]
Parameters
format?
- The format of each item in the list (default {position}. {guild.name} ({guild.id}) - {membersCount} members
).
sort?
- Sort the list by guild names, number of members, or channels. Available options:
name
- Sort items by guild names (default).
members
- Sort items by the number of members.
channels
- Sort items by the number of guilds.
roles
- Sort items by the number of roles.
list?
- Limits how many items should be listed per page (default 10
).
page?
- Limits how many pages there should be (default 1
).
sep?
- The separator for each item (default \n
).
All parameters have default values and are optional.
Available Formatting Options
{position}
- Returns the item's position in the list.
{guild.name}
- Returns the guild's name.
{guild.id}
- Returns the guild's ID.
{owner.name}
- Returns the owner's name.
{owner.id}
- Returns the owner's ID.
{membersCount}
- Returns the number of members in the guild.
{channelsCount}
- Returns the number of channels in the guild.
{roleCount}
- Returns the number of roles in the guild.
Source Code
module.exports = {
name: "$getClientGuilds",
type: "djs",
code: async (d) => {
const data = d.util.aoiFunc(d);
const [format, sort = "name", order = "asc", list = 10, page = 1, sep = "\n"] = data.inside.splits;
if (!Number.isInteger(parseInt(list))) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Integer Provided In List Parameter");
}
if (!Number.isInteger(parseInt(page))) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Integer Provided In Page Parameter");
}
const guilds = Array.from(d.client.guilds.cache.values());
if (sort) {
const validSortOptions = ["name", "members", "memberscount", "channels", "channelcount", "roles", "rolecount"];
const validOrderOptions = ["asc", "desc", "ascending", "descending"];
if (!validSortOptions.includes(sort.toLowerCase())) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Option Provided In Sort Parameter");
}
if (!validOrderOptions.includes(order.toLowerCase())) {
return d.aoiError.fnError(d, "custom", { inside: data.inside }, "Invalid Option Provided In Order Parameter");
}
const sortOrder = order.toLowerCase() === "asc" || order.toLowerCase() === "ascending" ? 1 : -1;
if (sort.toLowerCase() === "name") {
guilds.sort((a, b) => sortOrder * a.name.localeCompare(b.name));
} else if (sort.toLowerCase() === "members" || sort.toLowerCase() === "membercount") {
guilds.sort((a, b) => sortOrder * (a.memberCount - b.memberCount));
} else if (sort.toLowerCase() === "channels" || sort.toLowerCase() === "channelcount") {
guilds.sort((a, b) => sortOrder * (a.channels.cache.size - b.channels.cache.size));
} else if (sort.toLowerCase() === "roles" || sort.toLowerCase() === "rolecount") {
guilds.sort((a, b) => sortOrder * (a.roles.cache.size - b.roles.cache.size));
}
}
const result = [];
for (let i = 0; i < guilds.length; i++) {
const guild = guilds[i];
const owner = await d.client.users.fetch(guild.ownerId);
const replacer = {
"{position}": i + 1,
"{guild.name}": guild.name,
"{guild.id}": guild.id,
"{owner.name}": owner.username,
"{owner.id}": owner.id,
"{membersCount}": guild.memberCount,
"{channelsCount}": guild.channels.cache.size,
"{roleCount}": guild.roles.cache.size
};
let text = format || "{position}. {guild.name} ({guild.id}) - {membersCount} members";
for (const replace in replacer) {
text = text.replace(new RegExp(replace, "g"), replacer[replace]);
}
result.push(text);
}
data.result = result.slice(page * list - list, page * list).join(sep);
return { code: d.util.setCode(data) };
},
}
Example
This will return a list of all guilds alphabetically with the specified format.
client.command({
name: "getClientGuilds",
code: `$getClientGuilds[{position}. {guild.name} ({guild.id}) - {membersCount} members;name;asc]`
});