Fix: Modify load-commands.ts to support js
Some checks failed
Release / release-image (push) Failing after 1m46s
Release / deploy (push) Has been skipped

This commit is contained in:
2024-10-13 14:57:34 +00:00
parent cab904a924
commit cb62c533b2

View File

@@ -1,8 +1,8 @@
import path from 'path'; import path from 'path';
import {readdirSync} from 'fs'; import { readdir } from 'node:fs/promises';
import {ExtendedClient} from '../classes/extendedclient'; import { ExtendedClient } from '../classes/extendedclient';
import {logger} from '../logger'; import { logger } from '../logger';
export async function loadCommands(client: ExtendedClient): Promise<Array<string>>{ export async function loadCommands(client: ExtendedClient): Promise<Array<string>>{
const foldersPath = path.join(__dirname, '../commands'); const foldersPath = path.join(__dirname, '../commands');
@@ -10,7 +10,9 @@ export async function loadCommands(client: ExtendedClient): Promise<Array<string
const commands: Array<string> = []; const commands: Array<string> = [];
for(const folder of commandFolders){ for(const folder of commandFolders){
const commandsPath = path.join(foldersPath, folder); 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){ for(const file of commandsFiles){
const filePath = path.join(commandsPath, file); const filePath = path.join(commandsPath, file);
const data = await import(filePath); const data = await import(filePath);