Creating a event
You can create events simular too commands. A event must be a class extending from the Event
class.
const { Event } = require("gcommands")
module.exports = class extends Event {};
//or
const { Event } = require("gcommands")
class Message extends Event {};
module.exports = Message;
1
2
3
4
5
6
7
8
9
10
2
3
4
5
6
7
8
9
10
We can set the name
(event), once
and ws
. You can also use the EventOptionsBuilder
explained here
const { Event } = require("gcommands")
module.exports = class extends Event {
constructor(client) {
super(client, {
name: "messageCreate",
once: false,
ws: false
})
}
};
1
2
3
4
5
6
7
8
9
10
11
2
3
4
5
6
7
8
9
10
11
Next we add the run function.
async run(client, message) {
console.log(`${message.author.tag} -> ${message.content}`)
}
1
2
3
2
3
Resulting code
const { Event } = require("gcommands")
module.exports = class extends Event {
constructor(client) {
super(client, {
name: "messageCreate",
once: false,
ws: false
})
}
async run(client, message) {
console.log(`${message.author.tag} -> ${message.content}`)
}
};
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
2
3
4
5
6
7
8
9
10
11
12
13
14
15