File tree Expand file tree Collapse file tree 1 file changed +37
-0
lines changed
apps/website/docs/guide/02-commands Expand file tree Collapse file tree 1 file changed +37
-0
lines changed Original file line number Diff line number Diff line change 1
1
---
2
2
title : after function
3
3
---
4
+
5
+ The ` after ` function allows you to execute a callback after a command
6
+ has been executed. This is useful for performing actions that should
7
+ occur after the command has completed, such as logging or cleanup
8
+ tasks.
9
+
10
+ ## Usage
11
+
12
+ ``` ts title="src/app/commands/ping.ts"
13
+ import {
14
+ type CommandData ,
15
+ type ChatInputCommand ,
16
+ after ,
17
+ } from ' commandkit' ;
18
+
19
+ export const command: CommandData = {};
20
+
21
+ export const chatInput: ChatInputCommand = async (ctx ) => {
22
+ after (() => {
23
+ // This code will be executed after the command has been executed
24
+ console .log (' Command has been executed' );
25
+ });
26
+
27
+ await ctx .interaction .reply ({
28
+ content: ' Hello World' ,
29
+ ephemeral: true ,
30
+ });
31
+ };
32
+ ```
33
+
34
+ :::info
35
+
36
+ The ` after ` function is guaranteed to be called after the command has
37
+ been executed, regardless of whether the command was successful or
38
+ not.
39
+
40
+ :::
You can’t perform that action at this time.
0 commit comments