From cb62c533b2aea159eada1f54e22a798ce9904814 Mon Sep 17 00:00:00 2001 From: ytshih Date: Sun, 13 Oct 2024 14:57:34 +0000 Subject: [PATCH] Fix: Modify load-commands.ts to support js --- init/load-commands.ts | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/init/load-commands.ts b/init/load-commands.ts index bc907ff..1714ecf 100644 --- a/init/load-commands.ts +++ b/init/load-commands.ts @@ -1,8 +1,8 @@ import path from 'path'; -import {readdirSync} from 'fs'; +import { readdir } from 'node:fs/promises'; -import {ExtendedClient} from '../classes/extendedclient'; -import {logger} from '../logger'; +import { ExtendedClient } from '../classes/extendedclient'; +import { logger } from '../logger'; export async function loadCommands(client: ExtendedClient): Promise>{ const foldersPath = path.join(__dirname, '../commands'); @@ -10,7 +10,9 @@ export async function loadCommands(client: ExtendedClient): Promise = []; for(const folder of commandFolders){ const commandsPath = path.join(foldersPath, folder); - const commandsFiles = readdirSync(commandsPath).filter(file => file.endsWith('.ts')); + 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); @@ -22,4 +24,4 @@ export async function loadCommands(client: ExtendedClient): Promise