@getsolara/solara.js
Version:
A lightweight and modular Discord bot framework built on discord.js v14, with truly optional feature packages.
26 lines • 1.32 kB
JavaScript
const { ChannelType } = require('discord.js');
module.exports = {
name: "$channelCount",
description: "Returns the total number of channels (excluding categories) in the current guild or the guild specified by ID.",
takesBrackets: true,
execute: async (context, args) => {
const guildId = args[0]?.trim();
let targetGuild = null;
if (guildId) {
try {
targetGuild = await context.client.guilds.fetch(guildId);
await targetGuild.channels.fetch();
} catch (e) { return `[Error: Could not find guild with ID ${guildId}]`; }
} else {
targetGuild = context.guild;
if (!targetGuild) return "[Error: $channelCount requires guild context when no ID provided]";
try { await targetGuild.channels.fetch(); }
catch(e) { console.warn(`$channelCount: Failed to fetch channels: ${e.message}`); return "[Error: Failed to fetch channels]"; }
}
if (targetGuild) {
const channelCount = targetGuild.channels.cache.filter(c => c.type !== ChannelType.GuildCategory).size;
return channelCount.toString();
}
return "[Error: $channelCount - Could not determine guild context or fetch guild by ID]";
}
};