Skip to content

Commit e799774

Browse files
committed
docs: add section on handling discord.js events
1 parent f38ba1f commit e799774

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

apps/website/docs/guide/01-getting-started/03-setup-commandkit-manually.mdx

+14
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,20 @@ This command will reply with "Pong!" when the user runs the `/ping` slash comman
7070
Prefixes for your message (legacy) commands can be changed. Learn more [here](/docs/next/guide/resolve-message-commands-prefix).
7171
:::
7272

73+
## Adding events
74+
75+
To register and handle events emitted by discord.js, create a folder inside the `src/app` directory called `events` and create a folder with the name of the discord.js event you'd like to handle (e.g. ready, messageCreate, etc). This example will use the `ready` event.
76+
77+
In the `src/app/events/{eventName}` directory, you can create files which will export default functions that will be called when the respective event is emitted by discord.js. Following the `ready` event example mentioned above, you may want to log when your bot comes online. The function for that will look like so:
78+
79+
```ts title="src/app/events/log.ts"
80+
import type { Client } from 'discord.js';
81+
82+
export default function (client: Client<true>) {
83+
console.log(`Logged in as ${client.user.username}!`);
84+
}
85+
```
86+
7387
## Running the app in development
7488

7589
To run your application in development mode, you can use the `commandkit dev` command in your terminal. This will automatically reload the bot when you make changes to your code.

0 commit comments

Comments
 (0)