Files
amane-tanikaze-dcbot/init/load-commands.ts
ytshih e7331498f4
All checks were successful
Release / release-image (push) Successful in 2m2s
Release / deploy (push) Successful in 46s
Fix: change readdir to async
2024-10-13 14:59:46 +00:00

28 lines
1.1 KiB
TypeScript

import path from 'path';
import { readdir } from 'node:fs/promises';
import { ExtendedClient } from '../classes/extendedclient';
import { logger } from '../logger';
export async function loadCommands(client: ExtendedClient): Promise<Array<string>>{
const foldersPath = path.join(__dirname, '../commands');
const commandFolders = await readdir(foldersPath);
const commands: Array<string> = [];
for(const folder of commandFolders){
const commandsPath = path.join(foldersPath, folder);
const commandsFiles = path.basename(__filename).endsWith('.ts')
? (await readdir(commandsPath)).filter(file => file.endsWith('.ts'))
: (await readdir(commandsPath)).filter(file => file.endsWith('.js'));
for(const file of commandsFiles){
const filePath = path.join(commandsPath, file);
const data = await import(filePath);
if(data.command !== undefined){
client.commands.set(data.command.name, data.command);
commands.push(data.command.build().toJSON());
}else
logger.warning(`The command at ${filePath} is missing required properties.`);
}
}
return commands;
}