Skip to content

Commit eff1535

Browse files
committed
document custom events
1 parent 884cc0f commit eff1535

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,39 @@
11
---
22
title: Custom events
33
---
4+
5+
CommandKit also supports using custom events in the `events`
6+
directory. Custom events must be defined in a namespaced directory,
7+
which are primarily handled by plugins. For example, if you have a
8+
custom event called `guildMemberBoost`, you can create a file called
9+
`src/app/events/(custom)/guildMemberBoost/handler.ts` which will be
10+
handled by the appropriate plugins.
11+
12+
:::info
13+
14+
Event namespace directories are not the same as
15+
[command categories](../02-commands/06-category-directory.mdx) as they
16+
serve a different purpose.
17+
18+
:::
19+
20+
The usage of custom events is the same way as
21+
[Discord.js events](./01-discordjs-events.mdx). The only difference is
22+
that these events are namespaced and are primarily handled by plugins.
23+
24+
## How plugins execute namespaced events
25+
26+
If you're developing a plugin, you can trigger a custom event in your
27+
application. Here's an example of how you can trigger a custom
28+
`guildMemberBoost` event under the `custom` namespace.
29+
30+
```ts
31+
commandkit.events.to('custom').emit('guildMemberBoost', {
32+
member: member,
33+
guild: guild,
34+
});
35+
```
36+
37+
This will ensure every file inside the
38+
`src/app/events/(custom)/guildMemberBoost` directory is executed jue
39+
like regular [Discord.js events](./01-discordjs-events.mdx)

0 commit comments

Comments
 (0)