@@ -17,6 +17,12 @@ $ npm install necord discord.js
1717To utilize Necord in your project, import the ` NecordModule ` and configure it with the necessary options.
1818
1919``` typescript
20+ @@filename (app .module )
21+ import { Module } from ' @nestjs/common' ;
22+ import { NecordModule } from ' necord' ;
23+ import { IntentsBitField } from ' discord.js' ;
24+ import { AppService } from ' ./app.service' ;
25+
2026@Module ({
2127 imports: [
2228 NecordModule .forRoot ({
@@ -35,6 +41,11 @@ export class AppModule {}
3541With this setup, you can inject the ` AppService ` into your providers to easily register commands, events, and more.
3642
3743``` typescript
44+ @@filename (app .service )
45+ import { Injectable , Logger } from ' @nestjs/common' ;
46+ import { Context , On , Once , ContextOf } from ' necord' ;
47+ import { Client } from ' discord.js' ;
48+
3849@Injectable ()
3950export class AppService {
4051 private readonly logger = new Logger (AppService .name );
@@ -62,6 +73,10 @@ You may have noticed the `@Context` decorator in the examples above. This decora
6273Here's how to create a simple command handler for messages using the ` @TextCommand ` decorator.
6374
6475``` typescript
76+ @@filename (app .commands )
77+ import { Injectable } from ' @nestjs/common' ;
78+ import { Context , TextCommand , TextCommandContext , Arguments } from ' necord' ;
79+
6580@Injectable ()
6681export class AppCommands {
6782 @TextCommand ({
@@ -81,7 +96,7 @@ export class AppCommands {
8196
8297Application commands provide a native way for users to interact with your app within the Discord client. There are three types of application commands that can be accessed through different interfaces: chat input, message context menu (accessed by right-clicking a message), and user context menu (accessed by right-clicking a user).
8398
84- <figure ><img src =" https://i.imgur.com/4EmG8G8.png " /></figure >
99+ <figure ><img class = " illustrative-image " src =" https://i.imgur.com/4EmG8G8.png " /></figure >
85100
86101#### Slash commands
87102
@@ -90,6 +105,10 @@ Slash commands are an excellent way to engage with users in a structured manner.
90105To define a slash command using Necord, you can use the ` SlashCommand ` decorator.
91106
92107``` typescript
108+ @@filename (app .commands )
109+ import { Injectable } from ' @nestjs/common' ;
110+ import { Context , SlashCommand , SlashCommandContext } from ' necord' ;
111+
93112@Injectable ()
94113export class AppCommands {
95114 @SlashCommand ({
@@ -109,6 +128,9 @@ export class AppCommands {
109128You can define parameters for your slash commands using option decorators. Let's create a ` TextDto ` class for this purpose:
110129
111130``` typescript
131+ @@filename (text .dto )
132+ import { StringOption } from ' necord' ;
133+
112134export class TextDto {
113135 @StringOption ({
114136 name: ' text' ,
@@ -122,6 +144,11 @@ export class TextDto {
122144You can then use this DTO in the ` AppCommands ` class:
123145
124146``` typescript
147+ @@filename (app .commands )
148+ import { Injectable } from ' @nestjs/common' ;
149+ import { Context , SlashCommand , Options , SlashCommandContext } from ' necord' ;
150+ import { TextDto } from ' ./length.dto' ;
151+
125152@Injectable ()
126153export class AppCommands {
127154 @SlashCommand ({
@@ -146,6 +173,11 @@ For a complete list of built-in option decorators, check out [this documentation
146173To implement autocomplete functionality for your slash commands, you'll need to create an interceptor. This interceptor will handle requests as users type in the autocomplete field.
147174
148175``` typescript
176+ @@filename (cats - autocomplete .interceptor )
177+ import { Injectable } from ' @nestjs/common' ;
178+ import { AutocompleteInteraction } from ' discord.js' ;
179+ import { AutocompleteInterceptor } from ' necord' ;
180+
149181@Injectable ()
150182class CatsAutocompleteInterceptor extends AutocompleteInterceptor {
151183 public transformOptions(interaction : AutocompleteInteraction ) {
@@ -168,6 +200,9 @@ class CatsAutocompleteInterceptor extends AutocompleteInterceptor {
168200You will also need to mark your options class with ` autocomplete: true ` :
169201
170202``` typescript
203+ @@filename (cat .dto )
204+ import { StringOption } from ' necord' ;
205+
171206export class CatDto {
172207 @StringOption ({
173208 name: ' cat' ,
@@ -182,6 +217,12 @@ export class CatDto {
182217Finally, apply the interceptor to your slash command:
183218
184219``` typescript
220+ @@filename (cats .commands )
221+ import { Injectable , UseInterceptors } from ' @nestjs/common' ;
222+ import { Context , SlashCommand , Options , SlashCommandContext } from ' necord' ;
223+ import { CatDto } from ' /cat.dto' ;
224+ import { CatsAutocompleteInterceptor } from ' ./cats-autocomplete.interceptor' ;
225+
185226@Injectable ()
186227export class CatsCommands {
187228 @UseInterceptors (CatsAutocompleteInterceptor )
@@ -205,6 +246,11 @@ export class CatsCommands {
205246User commands appear on the context menu that appears when right-clicking (or tapping) on users. These commands provide quick actions that target users directly.
206247
207248``` typescript
249+ @@filename (app .commands )
250+ import { Injectable } from ' @nestjs/common' ;
251+ import { Context , UserCommand , UserCommandContext , TargetUser } from ' necord' ;
252+ import { User } from ' discord.js' ;
253+
208254@Injectable ()
209255export class AppCommands {
210256 @UserCommand ({ name: ' Get avatar' })
@@ -228,6 +274,11 @@ export class AppCommands {
228274Message commands show up in the context menu when right-clicking on messages, allowing for quick actions relevant to those messages.
229275
230276``` typescript
277+ @@filename (app .commands )
278+ import { Injectable } from ' @nestjs/common' ;
279+ import { Context , MessageCommand , MessageCommandContext , TargetMessage } from ' necord' ;
280+ import { Message } from ' discord.js' ;
281+
231282@Injectable ()
232283export class AppCommands {
233284 @MessageCommand ({ name: ' Copy Message' })
@@ -245,6 +296,10 @@ export class AppCommands {
245296[ Buttons] ( https://discord.com/developers/docs/interactions/message-components#buttons ) are interactive elements that can be included in messages. When clicked, they send an [ interaction] ( https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object ) to your application.
246297
247298``` typescript
299+ @@filename (app .components )
300+ import { Injectable } from ' @nestjs/common' ;
301+ import { Context , Button , ButtonContext } from ' necord' ;
302+
248303@Injectable ()
249304export class AppComponents {
250305 @Button (' BUTTON' )
@@ -259,12 +314,16 @@ export class AppComponents {
259314[ Select menus] ( https://discord.com/developers/docs/interactions/message-components#select-menus ) are another type of interactive component that appears on messages. They provide a dropdown-like UI for users to select options.
260315
261316``` typescript
317+ @@filename (app .components )
318+ import { Injectable } from ' @nestjs/common' ;
319+ import { Context , StringSelect , StringSelectContext , SelectedStrings } from ' necord' ;
320+
262321@Injectable ()
263322export class AppComponents {
264323 @StringSelect (' SELECT_MENU' )
265324 public onSelectMenu(
266325 @Context () [interaction ]: StringSelectContext ,
267- @Values () values : string [],
326+ @SelectedStrings () values : string [],
268327 ) {
269328 return interaction .reply ({ content: ` You selected: ${values .join (' , ' )} ` });
270329 }
0 commit comments