MCPcopy Create free account
hub / github.com/codebymitch/TitanBot / createCategoryCommandsMenu

Function createCategoryCommandsMenu

src/handlers/helpSelectMenus.js:121–237  ·  view source on GitHub ↗
(category, client)

Source from the content-addressed store, hash-verified

119}
120
121async function createCategoryCommandsMenu(category, client) {
122 const categoryName = formatCategoryName(category);
123 const icon = CATEGORY_ICONS[categoryName] || "🔍";
124
125 const categoryCommands = [];
126
127 try {
128 const categoryPath = path.join(__dirname, "../commands", category);
129 const commandFiles = (await fs.readdir(categoryPath))
130 .filter((file) => file.endsWith(".js"))
131 .sort();
132
133 for (const file of commandFiles) {
134 const filePath = path.join(categoryPath, file);
135 const commandModule = await import(`file://${filePath}`);
136 const command = commandModule.default;
137 const commandData = normalizeCommandData(command);
138
139 if (commandData) {
140 if (
141 commandData.name === "help" ||
142 commandData.name === "commandlist"
143 )
144 continue;
145
146 categoryCommands.push(...buildHelpEntries(command, categoryName));
147 }
148 }
149 } catch (error) {
150 logger.error(
151 `Error reading commands from category ${category}:`,
152 error,
153 );
154 }
155
156 categoryCommands.sort((a, b) => a.displayName.localeCompare(b.displayName));
157
158 let registeredCommands = new Collection();
159 try {
160 if (client?.application?.commands?.fetch) {
161 const commands = await client.application.commands.fetch();
162 for (const cmd of commands.values()) {
163 registeredCommands.set(cmd.name, cmd);
164 }
165 }
166 } catch (error) {
167 logger.error('Error fetching registered commands:', error);
168 }
169
170 const embed = createEmbed({
171 title: `${icon} ${categoryName} Commands`,
172 description: categoryCommands.length > 0
173 ? `Click any command mention below to use it.`
174 : `No commands found in the **${categoryName}** category.`
175 });
176
177 if (categoryCommands.length > 0) {
178 const commandMentions = categoryCommands

Callers 1

executeFunction · 0.85

Calls 7

createEmbedFunction · 0.90
createButtonFunction · 0.90
normalizeCommandDataFunction · 0.85
buildHelpEntriesFunction · 0.85
formatCategoryNameFunction · 0.70
setMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected