File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
apps/website/docs/guide/03-events Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
title : Custom events
3
3
---
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 )
You can’t perform that action at this time.
0 commit comments