forked from Supositware/Haha-Yes
Moving events in their own folders
This commit is contained in:
parent
851112de0a
commit
d44fabf554
4 changed files with 28 additions and 5 deletions
7
events/process/unhandledRejection.js
Normal file
7
events/process/unhandledRejection.js
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
export default {
|
||||||
|
name: 'unhandledRejection',
|
||||||
|
once: true,
|
||||||
|
async execute(error) {
|
||||||
|
console.error('Unhandled promise rejection:', error);
|
||||||
|
}
|
||||||
|
}
|
26
index.js
26
index.js
|
@ -24,12 +24,12 @@ for (const file of commandFiles) {
|
||||||
client.commands.set(command.data.name, command);
|
client.commands.set(command.data.name, command);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load events from the events folder
|
// Load client events from the events folder
|
||||||
const eventsPath = path.join(__dirname, 'events');
|
const clientEventsPath = path.join(__dirname, 'events/client');
|
||||||
const eventFiles = fs.readdirSync(eventsPath).filter(file => file.endsWith('.js'));
|
const clientEventFiles = fs.readdirSync(clientEventsPath).filter(file => file.endsWith('.js'));
|
||||||
|
|
||||||
for (const file of eventFiles) {
|
for (const file of clientEventFiles) {
|
||||||
const filePath = path.join(eventsPath, file);
|
const filePath = path.join(clientEventsPath, file);
|
||||||
let event = await import(filePath);
|
let event = await import(filePath);
|
||||||
event = event.default;
|
event = event.default;
|
||||||
if (event.once) {
|
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);
|
client.login(token);
|
||||||
|
|
Loading…
Reference in a new issue