Skip to content

Commit 15f7a4d

Browse files
committed
document stopEvents() function
1 parent 75b5ae2 commit 15f7a4d

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: stopEvents function
3+
---
4+
5+
The `stopEvents()` function is a utility function that allows you to
6+
stop the execution of the events chain in CommandKit. This is useful
7+
when you want to prevent further event handlers from being executed
8+
after a certain point. It is typically used in the context of event
9+
handlers to control the flow of execution.
10+
11+
## Usage
12+
13+
```ts title="src/app/events/messageCreate/event.ts"
14+
import type { Message } from 'discord.js';
15+
import { stopEvents } from 'commandkit';
16+
17+
export default async function (message: Message) {
18+
console.log('Message received:', message.content);
19+
20+
// Stop further event handlers of messageCreate from being executed after this point
21+
stopEvents();
22+
// code below will not be executed
23+
}
24+
```
25+
26+
:::warning
27+
28+
Calling `stopEvents()` in a try/catch block may lead to unexpected
29+
behavior.
30+
31+
:::
32+
33+
:::info
34+
35+
At this time, the `stopEvents()` function is only available for
36+
[Discord.js events](./01-discordjs-events.mdx), and not for custom
37+
namespaced events.
38+
39+
:::

0 commit comments

Comments
 (0)