### Revert Commit Example Source: https://github.com/necordjs/necord.org/blob/master/content/contributing/commit-convention.mdx Demonstrates the format for a revert commit. It starts with 'revert:', followed by the header of the commit being reverted. The body must state 'This reverts commit .' ```text revert: feat(user): add new login endpoint This reverts commit abc123def456. ``` -------------------------------- ### Basic NestJS Discord Bot Setup Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/techniques/sharding.mdx This snippet shows the basic setup for a NestJS Discord bot application. It's a starting point for integrating Discord functionality into a NestJS project. ```typescript import { NestFactory } from '@nestjs/core' import { DiscordModule } from '@nestjsplus/discord' ``` -------------------------------- ### Install Lavalink Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/recipes/lavalink.mdx Install the Lavalink client for your project using npm or yarn. ```bash npm install @lavalink/client # or yarn add @lavalink/client ``` -------------------------------- ### Install Necord.js Dependencies Source: https://github.com/necordjs/necord.org/blob/master/README.md Install project dependencies using Yarn. This command is essential before starting local development. ```bash yarn ``` -------------------------------- ### Install @necord/localization Source: https://github.com/necordjs/necord.org/blob/master/content/recipes/localization.mdx Install the localization module along with Necord and discord.js using npm or yarn. ```bash npm i @necord/localization necord discord.js ``` -------------------------------- ### Install Necord and Discord.js Source: https://github.com/necordjs/necord.org/blob/master/i18n/bn/docusaurus-plugin-content-docs/current/getting-started.mdx Install the necessary packages for Necord and Discord.js using npm or yarn. ```bash npm install necord discord.js ``` ```bash yarn add necord discord.js ``` -------------------------------- ### Start Necord.js Local Development Server Source: https://github.com/necordjs/necord.org/blob/master/README.md Starts a local development server for Necord.js. Changes are reflected live without requiring a server restart. ```bash yarn start ``` -------------------------------- ### Install Necord Pagination Source: https://github.com/necordjs/necord.org/blob/master/content/recipes/pagination.mdx Install the necessary packages for Necord pagination using npm or yarn. ```bash $ npm i @necord/pagination necord discord.js ``` -------------------------------- ### Install Necord Schematics Source: https://github.com/necordjs/necord.org/blob/master/content/cli.mdx Install the Necord Schematics globally and as a development dependency. ```bash npm install -g @nestjs/cli npm install -D @necord/schematics ``` -------------------------------- ### Install class-validator and class-transformer Source: https://github.com/necordjs/necord.org/blob/master/content/techniques/validation.mdx Install the necessary packages for data validation and transformation. ```bash $ npm install class-validator class-transformer ``` -------------------------------- ### Run the Application Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/getting-started.mdx Use npm or yarn to start your Necord.js application. This command will compile and run your bot. ```bash npm run start:dev # or yarn start:dev ``` -------------------------------- ### Install class-validator Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/techniques/validation.mdx Install the class-validator package for enabling validation decorators. ```bash npm install class-validator class-transformer ``` -------------------------------- ### Custom Command Registration Service Example Source: https://github.com/necordjs/necord.org/blob/master/i18n/ro/docusaurus-plugin-content-docs/current/faq.mdx This example demonstrates how to create a custom registration service for commands when Necord's auto-registration is disabled. It is useful for dynamic, conditional, or asynchronous command loading. ```typescript import { NecordModule } from '@necord/core'; @Module({ imports: [ NecordModule.forRoot({ token: 'YOUR_BOT_TOKEN', skipRegistration: true, }), ], }) export class AppModule {} ``` -------------------------------- ### Install Necord Localization Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/recipes/localization.mdx Install the Necord localization package using npm or yarn. ```bash npm install @necord/plugin-localization yarn add @necord/plugin-localization ``` -------------------------------- ### Commit Body Example Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/contributing/commit-convention.mdx Example of a commit body providing more context about the changes. ```text More detailed explanation of the changes. This section can be multiple lines long and should provide context that is not obvious from the subject line alone. ``` -------------------------------- ### Install Necord.js Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/getting-started.mdx Use npm or yarn to install the Necord.js library. This is the first step to integrating Necord.js into your project. ```bash npm install discord.js # or yarn add discord.js ``` -------------------------------- ### Run the NestJS Application Source: https://github.com/necordjs/necord.org/blob/master/content/getting-started.mdx Start your NestJS application to begin listening for Discord API events. This command assumes you have a start script configured in your package.json. ```bash $ npm run start ``` -------------------------------- ### Install Necord CLI Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/cli.mdx Install the Necord CLI globally using npm or yarn. This command is used for setting up the CLI tool. ```bash npm install -g @necord/schematics ``` -------------------------------- ### Install @necord/lavalink Package Source: https://github.com/necordjs/necord.org/blob/master/content/recipes/lavalink.mdx Install the necessary packages for Lavalink integration. This includes @necord/lavalink, necord, discord.js, and lavalink-client. ```bash npm i @necord/lavalink necord discord.js lavalink-client ``` -------------------------------- ### Install Necord and Discord.js Source: https://github.com/necordjs/necord.org/blob/master/content/getting-started.mdx Install the necessary packages for Necord and Discord.js using npm or yarn. Ensure you have Node.js v18.0.0 or newer. ```bash npm install necord discord.js ``` -------------------------------- ### Install Necord using npm or yarn Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/intro.mdx Use this command to install Necord in your project. It is recommended to use npm or yarn for package management. ```bash npm install @necord/core # or yarn add @necord/core ``` -------------------------------- ### Create a Dynamic Select Menu Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/interactions/message-components.mdx Example of creating a select menu dynamically. This allows for menus with options generated based on data. ```typescript { label: 'Red', value: 'Red' } { label: 'Blue', value: 'Blue' } { label: 'Yellow', value: 'Yellow' } ``` ```typescript { Injectable } ${item} ``` -------------------------------- ### Dynamic Modal Example Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/interactions/modals.mdx Example of a dynamic modal, likely used for user input or interaction. Ensure correct imports and context are provided. ```typescript import { Injectable } from "@nestjs/common" ${value} ``` -------------------------------- ### Commit Scope Examples Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/contributing/commit-convention.mdx Illustrates how to use scopes to indicate the part of the codebase affected by the commit. ```text feat(api): add "new-endpoint" fix(ui): resolve "layout-issue" ``` -------------------------------- ### Implement Custom Locale Resolver Source: https://github.com/necordjs/necord.org/blob/master/content/recipes/localization.mdx Create a custom locale resolver by implementing the `LocaleResolver` interface. This example shows how to get the guild's locale. ```typescript import { CommandContext, LocaleResolver } from '@necord/localization'; import { ExecutionContext, Injectable } from '@nestjs/common'; import { NecordExecutionContext } from 'necord'; @Injectable() export class GuildResolver implements LocaleResolver { resolve(context: ExecutionContext): string | string[] | undefined { const necordContext = NecordExecutionContext.create(context); const [interaction] = necordContext.getContext(); return interaction.guildLocale; } } ``` -------------------------------- ### Play Command with Lavalink Source: https://github.com/necordjs/necord.org/blob/master/content/recipes/lavalink.mdx Implement a slash command to play music tracks using Necord and Lavalink. This snippet shows how to create or get a player, connect to a voice channel, search for tracks, add them to the queue, and start playback. It also includes basic error handling and replies to the user. ```typescript import { Injectable, UseInterceptors } from '@nestjs/common'; import { NecordLavalinkService, PlayerManagerService } from '@necord/lavalink'; import { Context, Options, SlashCommand, SlashCommandContext } from 'necord'; import { QueryDto } from './query.dto'; import { SourceAutocompleteInterceptor } from 'source.autocomplete'; @Injectable() export class AppCommands { public constructor( private readonly playerManager: PlayerManagerService, private readonly lavalinkService: NecordLavalinkService ) {} @UseInterceptors(SourceAutocompleteInterceptor) @SlashCommand({ name: 'play', description: 'play a track', }) public async onPlay( @Context() [interaction]: SlashCommandContext, @Options() { query, source }: QueryDto, ) { const player = this.playerManager.get(interaction.guild.id) ?? this.playerManager.create({ ...this.lavalinkService.extractInfoForPlayer(interaction), // optional configurations: selfDeaf: true, selfMute: false, volume: 100, }); await player.connect(); const res = await player.search( { query, source: source ?? 'soundcloud' }, interaction.user.id, ); await player.queue.add(res.tracks[0]); if (!player.playing) await player.play(); // It's extremely recommended to use `trackStart` event for this announcement return interaction.reply({ content: `Now playing ${res.tracks[0].info.title}`, }); } } ``` -------------------------------- ### Play Command Implementation with Lavalink Source: https://github.com/necordjs/necord.org/blob/master/i18n/bn/docusaurus-plugin-content-docs/current/recipes/lavalink.mdx Implement a slash command to play tracks using Necord's Lavalink integration. This snippet shows how to create or get a player, connect to voice, search for tracks, add them to the queue, and start playback. It also includes optional player configurations like selfDeaf, selfMute, and volume. ```typescript import { Injectable, UseInterceptors } from '@nestjs/common'; import { NecordLavalinkService, PlayerManagerService } from '@necord/lavalink'; import { Context, Options, SlashCommand, SlashCommandContext } from 'necord'; import { QueryDto } from './query.dto'; import { SourceAutocompleteInterceptor } from 'source.autocomplete'; @Injectable() export class AppCommands { public constructor( private readonly playerManager: PlayerManagerService, private readonly lavalinkService: NecordLavalinkService ) {} @UseInterceptors(SourceAutocompleteInterceptor) @SlashCommand({ name: 'play', description: 'play a track', }) public async onPlay( @Context() [interaction]: SlashCommandContext, @Options() { query, source }: QueryDto, ) { const player = this.playerManager.get(interaction.guild.id) ?? this.playerManager.create({ ...this.lavalinkService.extractInfoForPlayer(interaction), // optional configurations: selfDeaf: true, selfMute: false, volume: 100, }); await player.connect(); const res = await player.search( { query, source: source ?? 'soundcloud' }, interaction.user.id, ); await player.queue.add(res.tracks[0]); if (!player.playing) await player.play(); // It's extremely recommended to use `trackStart` event for this announcement return interaction.reply({ content: `Now playing ${res.tracks[0].info.title}`, }); } } ``` -------------------------------- ### Install Dependencies Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/techniques/standalone-application.mdx Install necessary dependencies for your NestJS project using npm. ```bash npm install ``` -------------------------------- ### Basic Necord Application Setup Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/intro.mdx This snippet shows the basic structure for a Necord application module. Ensure you import necessary Necord and NestJS modules. ```typescript import { NecordModule } from '@necord/core'; import { Module } from '@nestjs/common'; import { IntentsBitField } from 'discord.js'; import { AppUpdate } from './app.update'; @Module({ imports: [ NecordModule.forRoot({ token: 'YOUR_BOT_TOKEN', intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMembers, IntentsBitField.Flags.GuildMessages, ], }), ], providers: [AppUpdate], }) export class AppModule {} ``` -------------------------------- ### Initialize Pagination Service Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/recipes/pagination.mdx Set up the NecordPaginationModule and PageBuilder for use in your application. This is typically done in the root module. ```typescript import { OnModuleInit, Injectable, } from '@nestjs/common'; import { NecordPaginationService, PageBuilder, } from '@necord/pagination'; import { Context, SlashCommand, SlashCommandContext, } from '@necord/common'; @Injectable() export class AppService implements OnModuleInit { public constructor( private readonly paginationService: NecordPaginationService ) {} public onModuleInit(): void { this.paginationService.setBuilder( new PageBuilder() .setClient(this.paginationService.getClient()) .setCommand( new SlashCommand({ name: 'pagination', description: 'Test pagination', }) ) ); } } ``` -------------------------------- ### Revert Commit Message Example Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/contributing/commit-convention.mdx Example of a commit message used to revert a previous commit. ```text revert: feat(api): add "new-feature" This reverts commit abc1234. ``` -------------------------------- ### Basic Listener Setup with @On and @Once Source: https://github.com/necordjs/necord.org/blob/master/content/listeners.mdx Use @Once for events that should only trigger once, like client readiness. Use @On for recurring events, such as warnings. Both decorators can be used in any injectable class. ```typescript import { Injectable, Logger } from '@nestjs/common'; import { Once, On, Context, ContextOf } from 'necord'; @Injectable() export class AppService { private readonly logger = new Logger(AppService.name); @Once('clientReady') public onReady(@Context() [client]: ContextOf<'clientReady'>) { this.logger.log(`Bot logged in as ${client.user.username}`); } @On('warn') public onWarn(@Context() [message]: ContextOf<'warn'>) { this.logger.warn(message); } } ``` -------------------------------- ### Commit Footer Examples Source: https://github.com/necordjs/necord.org/blob/master/i18n/ach/docusaurus-plugin-content-docs/current/contributing/commit-convention.mdx Examples of commit footers used for referencing issues, breaking changes, or co-authors. ```text BREAKING CHANGE: The API response format has changed. Closes #123 Co-authored-by: Jane Doe ``` -------------------------------- ### Declaring Slash Commands Source: https://context7.com/necordjs/necord.org/llms.txt Demonstrates how to declare simple slash commands, commands with typed options using DTOs, and guild-specific commands. ```APIDOC ## @SlashCommand — Slash commands Declare a Discord application slash command on any method inside an injectable class. Commands are automatically registered globally (or guild-only when `guilds` is set). Use `@Options()` to inject a typed DTO of command parameters. ```typescript // src/app.commands.ts import { Injectable } from '@nestjs/common'; import { Context, SlashCommand, SlashCommandContext, Options } from 'necord'; import { StringOption } from 'necord'; class EchoDto { @StringOption({ name: 'message', description: 'Text to echo', required: true }) message: string; } @Injectable() export class AppCommands { // Simple command — no options @SlashCommand({ name: 'ping', description: 'Replies with Pong!' }) public async onPing(@Context() [interaction]: SlashCommandContext) { return interaction.reply({ content: 'Pong!', ephemeral: true }); } // Command with a typed DTO option @SlashCommand({ name: 'echo', description: 'Echoes your message' }) public async onEcho( @Context() [interaction]: SlashCommandContext, @Options() { message }: EchoDto ) { return interaction.reply({ content: message }); } // Guild-specific command (registers instantly, no 1-hour cache) @SlashCommand({ name: 'secret', description: 'Only visible in the dev guild', guilds: [process.env.DEV_GUILD] }) public async onSecret(@Context() [interaction]: SlashCommandContext) { return interaction.reply({ content: 'This is a guild-only command!', ephemeral: true }); } } ``` ``` -------------------------------- ### NecordModule.forRoot - Static Module Setup Source: https://context7.com/necordjs/necord.org/llms.txt Register the Necord module synchronously in your root AppModule. Provide the bot token, Discord gateway intents, and an optional development guild ID for instant command registration during development. ```typescript // src/app.module.ts import { Module } from '@nestjs/common'; import { NecordModule } from 'necord'; import { IntentsBitField } from 'discord.js'; import { AppService } from './app.service'; @Module({ imports: [ NecordModule.forRoot({ token: process.env.DISCORD_TOKEN, intents: [ IntentsBitField.Flags.Guilds, IntentsBitField.Flags.GuildMessages, IntentsBitField.Flags.DirectMessages ], // Restrict commands to this guild during development (instant registration) development: [process.env.DISCORD_DEVELOPMENT_GUILD_ID] }) ], providers: [AppService] }) export class AppModule {} ``` -------------------------------- ### Generate a User Context Menu with Necord Schematics Source: https://context7.com/necordjs/necord.org/llms.txt Create a user context menu command using @necord/schematics. Define the name and strategy for the context menu. ```bash # Generate a user context menu nest g -c @necord/schematics context-menu --name get-avatar --strategy user ``` -------------------------------- ### Channel Select Menu Source: https://github.com/necordjs/necord.org/blob/master/i18n/ro/docusaurus-plugin-content-docs/current/interactions/message-components.mdx Demonstrates how to create and receive interactions for a Channel Select menu. ```APIDOC ## Channel Select Menu ### Description Handles interactions for selecting channels from a Discord message. ### Create Channel Select Menu ```typescript new ChannelSelectMenuBuilder() .setCustomId('CHANNEL_SELECT_MENU') .setPlaceholder('Select a channel') .setMaxValues(1) .setMinValues(1) ``` ### Receive Channel Select Interaction ```typescript import { Injectable } from '@nestjs/common'; import { Context, ChannelSelect, ChannelSelectContext, SelectedChannels, ISelectedChannels, } from 'necord'; @Injectable() export class AppComponents { @ChannelSelect('CHANNEL_SELECT_MENU') public onChannelSelect( @Context() [interaction]: ChannelSelectContext, @SelectedChannels() channels: ISelectedChannels, // Collection of channels ) { interaction.reply({ content: ` Selected channels - ${channels.map(channel => channel.id).join(',')} ` }); } } ``` ```