feat: improve component and command loading functions with directory existence checks
This commit is contained in:
@@ -8,7 +8,13 @@ export const modals: Collection<string, Modal> = new Collection<string, Modal>()
|
||||
export const selectmenus: Collection<string, SelectMenu> = new Collection<string, SelectMenu>();
|
||||
export const contextmenus: Collection<string, ContextMenu> = new Collection<string, ContextMenu>();
|
||||
|
||||
export function loadComponents(dir: string = path.join(__dirname, "..", "components")) {
|
||||
export function loadComponents(dir: string = path.resolve(__dirname, "../../components")) {
|
||||
// Evitar fallo si el directorio no existe en el entorno
|
||||
if (!fs.existsSync(dir)) {
|
||||
console.warn(`⚠️ Directorio de componentes no encontrado: ${dir}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
for (const file of files) {
|
||||
@@ -21,6 +27,7 @@ export function loadComponents(dir: string = path.join(__dirname, "..", "compone
|
||||
}
|
||||
|
||||
if (!file.endsWith(".ts") && !file.endsWith(".js")) continue;
|
||||
if (file.endsWith('.d.ts')) continue;
|
||||
|
||||
try {
|
||||
const imported = require(fullPath);
|
||||
|
||||
@@ -4,7 +4,13 @@ import { Collection } from "discord.js";
|
||||
|
||||
export const commands = new Collection<string, any>();
|
||||
|
||||
export function loadCommands(dir: string = path.join(__dirname, '..', 'commands')) {
|
||||
export function loadCommands(dir: string = path.resolve(__dirname, "../../commands")) {
|
||||
// Evitar fallo si el directorio no existe en el entorno
|
||||
if (!fs.existsSync(dir)) {
|
||||
console.warn(`⚠️ Directorio de comandos no encontrado: ${dir}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
for (const file of files) {
|
||||
@@ -16,7 +22,8 @@ export function loadCommands(dir: string = path.join(__dirname, '..', 'commands'
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!file.endsWith('.ts')) continue;
|
||||
if (!file.endsWith('.ts') && !file.endsWith('.js')) continue;
|
||||
if (file.endsWith('.d.ts')) continue;
|
||||
|
||||
const imported = require(fullPath);
|
||||
const command = imported.command ?? imported.default ?? imported;
|
||||
|
||||
@@ -2,7 +2,13 @@ import { bot } from "../../main";
|
||||
import path from "node:path";
|
||||
import * as fs from "node:fs";
|
||||
|
||||
export function loadEvents(dir: string = path.join(__dirname, "../events")) {
|
||||
export function loadEvents(dir: string = path.resolve(__dirname, "../../events")) {
|
||||
// Evitar fallo si el directorio no existe
|
||||
if (!fs.existsSync(dir)) {
|
||||
console.warn(`⚠️ Directorio de eventos no encontrado: ${dir}`);
|
||||
return;
|
||||
}
|
||||
|
||||
const files = fs.readdirSync(dir);
|
||||
|
||||
for (const file of files) {
|
||||
|
||||
Reference in New Issue
Block a user