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

Function createAllCommandsMenu

src/handlers/helpSelectMenus.js:239–370  ·  view source on GitHub ↗
(page = 1, client)

Source from the content-addressed store, hash-verified

237}
238
239export async function createAllCommandsMenu(page = 1, client) {
240 const commandsPerPage = 45;
241 const allCommands = [];
242
243 const commandsPath = path.join(__dirname, "../commands");
244 const categoryDirs = (
245 await fs.readdir(commandsPath, { withFileTypes: true })
246 )
247 .filter((dirent) => dirent.isDirectory())
248 .map((dirent) => dirent.name)
249 .sort();
250
251 for (const category of categoryDirs) {
252 try {
253 const categoryPath = path.join(
254 __dirname,
255 "../commands",
256 category,
257 );
258 const commandFiles = (await fs.readdir(categoryPath))
259 .filter((file) => file.endsWith(".js"))
260 .sort();
261
262 for (const file of commandFiles) {
263 const filePath = path.join(categoryPath, file);
264 const commandModule = await import(`file://${filePath}`);
265 const command = commandModule.default;
266 const commandData = normalizeCommandData(command);
267
268 if (commandData) {
269 if (
270 commandData.name === "help" ||
271 commandData.name === "commandlist"
272 )
273 continue;
274
275 const categoryName = formatCategoryName(category);
276
277 allCommands.push(...buildHelpEntries(command, categoryName));
278 }
279 }
280 } catch (error) {
281 logger.error(
282 `Error reading commands from category ${category}:`,
283 error,
284 );
285 }
286 }
287
288 allCommands.sort((a, b) => a.displayName.localeCompare(b.displayName));
289
290 let registeredCommands = new Collection();
291 try {
292 if (client?.application?.commands?.fetch) {
293 const commands = await client.application.commands.fetch();
294 for (const cmd of commands.values()) {
295 registeredCommands.set(cmd.name, cmd);
296 }

Callers 2

executeFunction · 0.90
executeFunction · 0.85

Calls 8

createEmbedFunction · 0.90
getPaginationRowFunction · 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