| 276 | } |
| 277 | |
| 278 | async loadHandlers() { |
| 279 | startupLog('Loading handlers...'); |
| 280 | const handlers = [ |
| 281 | { path: 'events', type: 'default', required: true }, |
| 282 | { path: 'interactions', type: 'default', required: true } |
| 283 | ]; |
| 284 | |
| 285 | for (const handler of handlers) { |
| 286 | try { |
| 287 | startupLog(`Loading handler: ${handler.path}`); |
| 288 | const module = await import(`./handlers/${handler.path}.js`); |
| 289 | const loaderFn = handler.type.startsWith('named:') |
| 290 | ? module[handler.type.split(':')[1]] |
| 291 | : module.default; |
| 292 | |
| 293 | if (typeof loaderFn === 'function') { |
| 294 | await loaderFn(this); |
| 295 | startupLog(`✅ Loaded ${handler.path}`); |
| 296 | } else { |
| 297 | throw new Error(`Invalid loader export from ${handler.path}`); |
| 298 | } |
| 299 | } catch (error) { |
| 300 | if (handler.required) { |
| 301 | logger.error(`❌ Failed to load required handler ${handler.path}:`, error.message); |
| 302 | throw error; |
| 303 | } else if (error.code !== 'MODULE_NOT_FOUND') { |
| 304 | logger.warn(`⚠️ Failed to load optional handler ${handler.path}:`, error.message); |
| 305 | } |
| 306 | } |
| 307 | } |
| 308 | } |
| 309 | |
| 310 | async registerCommands() { |
| 311 | try { |