diff --git a/events/interactionCreate.js b/events/client/interactionCreate.js similarity index 100% rename from events/interactionCreate.js rename to events/client/interactionCreate.js diff --git a/events/ready.js b/events/client/ready.js similarity index 100% rename from events/ready.js rename to events/client/ready.js diff --git a/events/process/unhandledRejection.js b/events/process/unhandledRejection.js new file mode 100644 index 00000000..86c29791 --- /dev/null +++ b/events/process/unhandledRejection.js @@ -0,0 +1,7 @@ +export default { + name: 'unhandledRejection', + once: true, + async execute(error) { + console.error('Unhandled promise rejection:', error); + } +} diff --git a/index.js b/index.js index 05b60003..61986d02 100644 --- a/index.js +++ b/index.js @@ -24,12 +24,12 @@ for (const file of commandFiles) { client.commands.set(command.data.name, command); } -// Load events from the events folder -const eventsPath = path.join(__dirname, 'events'); -const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js')); +// Load client events from the events folder +const clientEventsPath = path.join(__dirname, 'events/client'); +const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js')); -for (const file of eventFiles) { - const filePath = path.join(eventsPath, file); +for (const file of clientEventFiles) { + const filePath = path.join(clientEventsPath, file); let event = await import(filePath); event = event.default; if (event.once) { @@ -40,4 +40,20 @@ for (const file of eventFiles) { } } +// Load process events from the events folder +const processEventsPath = path.join(__dirname, 'events/process'); +const processEventFiles = fs.readdirSync(processEventsPath).filter(file => file.endsWith('.js')); + +for (const file of processEventFiles) { + const filePath = path.join(processEventsPath, file); + let event = await import(filePath); + event = event.default; + if (event.once) { + process.once(event.name, (...args) => event.execute(...args)); + } + else { + process.on(event.name, (...args) => event.execute(...args)); + } +} + client.login(token);