Events
WarningThis page is still a work in progress.
Discm automatically listens to events for you, so you will never have to call client.on
or client.once
.
Let’s create an event which listen for the ready
event, which is dispatched by discord when our bot is online, and send a message to the console letting us know the bot is online.
Make a new file in your events directory and name it whatever (recommended to use the name of the event).
// filename: events/ready.ts
import { DiscmEvent } from 'discm.js';
export default new DiscmEvent({
name: 'ready',
once: true,
run(client) {
client.logger.success(`Successfully logged in as ${client.user?.tag}`);
}
});
// filename: events/ready.js
const { DiscmEvent } = require('discm.js');
module.exports = new DiscmEvent({
name: 'ready',
once: true,
run(client) {
client.logger.success(`Successfully logged in as ${client.user?.tag}`);
}
});
Unlike commands, name
is required.
once
uses client.once
instead of client.on
to listen for the event.
The callback passes in the client as an argument, and then whatever additional arguments the event passes in (e.g. messageCreate
passes in message
).
NoteEvents
interactionCreate
andmessageCreate
are listened to be discm for commands, and will run your callback code after the command code.