event api¶
Events are applied using the following example (basically standard NodeJS EventEmitter syntax):
client.on('EVENT', // `EVENT` being any of the events listed in the documentation.
function (event) { // callback function, called when event is fired
console.log('Something happened!');
});
event object¶
You may have noticed that we are passing an event argument to the event binding function. This is actually not just data but an object with an API to help you deal with events without hassle. Not all events are the same, so please check the various plugin documentations to see what events are available. The following functions and attributes are always available:
-
network
¶
The network this event was triggered in.
Note
The reply functions are only going to succeed when the channel
or user
attribute is available.
-
reply
¶
Answer to a message (same channel/query as the event came from).
Example:
client.on('command', function (event) {
if (event.cmd === 'ping') event.reply('pong');
});
-
replyAction
¶
Answer to a message with an action (/me
). Works like reply(message)
.
-
replyNotice
¶
Answer to a message with a notice. Works like reply(message)
.
core events¶
-
ssl-error
¶
The ssl-error
event, fired when there was an error establishing an SSL connection. If you’re running with ssl_allow_invalid
this event will still fire, but coffea will continue connecting to the server afterwards.
Event attributes:
- None
Example:
client.on('ssl-error', function (event) {
console.error('SSL Error:', err);
});
-
disconnect
¶
The disconnect
event, fired when the client was disconnected from a network.
Event attributes:
- None
Example:
client.on('disconnect', function (event) {
console.log("We disconnected!");
});
-
event
¶
The event
event, fired when any other event is fired.
Example:
client.on('event', function (name, err, event) {
console.log(name, "event fired:", err, event);
});