mirror of
https://github.com/JonnyBro/JaBa.git
synced 2025-02-01 07:04:11 +05:00
feat: added event handler
This commit is contained in:
parent
9f82e45a67
commit
c77d66ea40
3 changed files with 36 additions and 1 deletions
|
@ -24,7 +24,7 @@ export class ExtendedClient extends Client {
|
|||
}
|
||||
|
||||
async registerModules() {
|
||||
await this.registerCommands(this.__dirname);
|
||||
await Promise.all([this.registerCommands(this.__dirname), this.registerEvents(this.__dirname)]);
|
||||
}
|
||||
|
||||
async registerCommands(baseDir) {
|
||||
|
@ -54,4 +54,18 @@ export class ExtendedClient extends Client {
|
|||
console.log(error);
|
||||
}
|
||||
}
|
||||
|
||||
async registerEvents(baseDir) {
|
||||
const eventFiles = await glob(`${baseDir}/../newEvents/**/*.js`);
|
||||
|
||||
for (const file of eventFiles) {
|
||||
const event = await this.importFile(file);
|
||||
|
||||
if (event.data.once) {
|
||||
this.once(event.data.name, event.run);
|
||||
} else {
|
||||
this.on(event.data.name, event.run);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
10
base/newEvent.js
Normal file
10
base/newEvent.js
Normal file
|
@ -0,0 +1,10 @@
|
|||
export default class BaseEvent {
|
||||
/**
|
||||
* @param {{ name: import("discord.js").ClientEvents, once: boolean}} options
|
||||
* @param {Function} run
|
||||
*/
|
||||
constructor(data, run) {
|
||||
this.data = data;
|
||||
this.run = run;
|
||||
}
|
||||
}
|
11
newEvents/ready.js
Normal file
11
newEvents/ready.js
Normal file
|
@ -0,0 +1,11 @@
|
|||
import Event from "../base/newEvent.js";
|
||||
|
||||
export default new Event(
|
||||
{
|
||||
name: "ready",
|
||||
once: true,
|
||||
},
|
||||
client => {
|
||||
console.log(client.user.tag + " is online!");
|
||||
},
|
||||
);
|
Loading…
Reference in a new issue