Skip to content

Listening discord events

First of all, you must tell seyfert where your events will be created by updating your config file.

seyfert.config.js
1
// @ts-check
2
const { config } = require('seyfert');
3
4
module.exports = config.bot({
5
token: process.env.BOT_TOKEN ?? "",
6
intents: ["Guilds"],
7
locations: {
8
base: "src",
9
output: "dist",
10
commands: "commands",
11
events: "events"
12
}
13
});

Then you can create a listener by exporting createEvent function into a file inside the events folder. Let’s see an example of how create a ready event:

src/events/botReady.ts
1
import { createEvent } from "seyfert";
2
3
export default createEvent({
4
data: { once: true, name: "botReady" },
5
run(user, client) {
6
client.logger.info(`${user.username} is ready`);
7
}
8
})

Let’s check another example with guildDelete event:

src/events/guildDelete.ts
1
import { createEvent } from "seyfert";
2
3
export default createEvent({
4
data: { name: "guildDelete" },
5
run(unguild, client) {
6
if (unguild.unavailable) return;
7
client.logger.info(`I have been kicked out of: ${unguild.id}`);
8
}
9
})

And that’s all, you can create as many events as you want. For further information you can check the list of all gateway events here.