Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

necord

necordjs10.7kMIT6.11.1TypeScript support: included

A module for creating Discord bots using NestJS, based on Discord.js

nest, nestjs, nestjs-module, discord, discordjs, discord bot, discord bot api, bot, bot api, bot framework

readme

Necord Logo

🤖 A module for creating Discord bots using NestJS, based on Discord.js

Documentation ✨Source code 🪡Examples 🛠️Community 💬

NPM Version NPM License NPM Downloads Last commit

About

This package uses the best of the Node.js world under the hood. Discord.js is the most powerful library for creating bots and Nest.js is a progressive framework for creating well-architectured applications. This module provides a fast and easy way of creating Discord bots and deep integration with your NestJS application.

Features

  • Simple. Flexible. Easy to use.
  • Ability to create custom decorators.
  • Interact with Discord (Slash Commands, Context Menus, Message Components, Listeners).
  • Full support of NestJS guards, interceptors, filters and pipes!

For questions and support, please use the Issues.

Installation

Node.js 18.0.0 or newer is required.

$ npm i necord discord.js
$ yarn add necord discord.js
$ pnpm add necord discord.js

Usage

Once the installation process is complete, we can import the NecordModule into the root AppModule:

import { NecordModule } from 'necord';
import { Module } from '@nestjs/common';
import { AppUpdate } from './app.update';

@Module({
    imports: [
        NecordModule.forRoot({
            token: 'DISCORD_BOT_TOKEN',
            intents: ['Guilds', 'GuildMessages', 'DirectMessages']
        })
    ],
    providers: [AppUpdate]
})
export class AppModule {
}

Then create app.update.ts file and add On/Once decorators for handling Discord API events:

import { Injectable, Logger } from '@nestjs/common';
import { Context, On, Once, ContextOf } from 'necord';
import { Client } from 'discord.js';

@Injectable()
export class AppUpdate {
    private readonly logger = new Logger(AppUpdate.name);

    public constructor(private readonly client: Client) {
    }

    @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);
    }
}

Whenever you need to handle any event data, use the Context decorator.

If you want to fully dive into Necord, check out these resources:

  • Necord Wiki - Official documentation of Necord.
  • Nest JS - A progressive framework for creating well-architectured applications.
  • Discord JS - The most powerful library for creating bots.
  • Discord API - Official documentation of Discord API.

Backers

Stay in touch

License

MIT © Alexey Filippov

changelog

Changelog

6.11.1 (2025-09-04)

Bug Fixes

  • CommandModule: update "ready" event to "clientReady" as "ready" is now deprecated (#1633) (771add4)
  • return brackets to local spec (8991866)

Styling

6.11.0 (2025-08-31)

Features

6.10.0 (2025-08-28)

Features

  • add custom listener decorator helpers (ab0c4d0)

6.9.1 (2025-07-17)

6.9.0 (2025-07-12)

Features

  • add support of request and transient scoped instances (4bba0df)

Bug Fixes

Refactor

Styling

6.8.14 (2025-05-15)

Bug Fixes

  • typings of slash commands (0b7e66d)

Styling

6.8.13 (2025-05-01)

6.8.9 (2025-04-27)

Bug Fixes

  • remove distributive omit (44c9215)

Styling

6.8.8 (2025-03-14)

Bug Fixes

6.8.7 - (2025-01-21)

Styling

6.8.4 - (2024-09-02)

Styling

6.8.3 - (2024-04-09)

Bug Fixes

  • Add undefined value for discovery meta (78f558d)

6.8.0 - (2024-03-14)

Features

  • Providers: Add emojis and user (#1117) (cf36b3c)

6.7.0 - (2024-03-11)

Documentation

6.6.0 - (2024-01-14)

Features

  • Add providers of client (8c65d72)

6.5.0 - (2023-12-19)

Refactor

  • Create register all commands fn (2de4b17)

Styling

6.4.1 - (2023-10-30)

Bug Fixes

  • Add event of client for message update (5d7d912)

6.4.0 - (2023-10-30)

Features

  • Add more flexibility for custom listeners (ec89cdb)

6.2.0 - (2023-10-23)

Refactor

  • Use modules for listeners and explorer (4759617)

6.1.8 - (2023-10-09)

Bug Fixes

  • Remove type of member permissions from subcommand and groups (df4683e)

6.1.5 - (2023-09-26)

Bug Fixes

  • Remove rewrite prototype of default value (263ca68)

6.1.4 - (2023-09-06)

Features

  • slash-command-discovery: Add getters for subcommands (1851628)

6.1.3 - (2023-09-01)

Bug Fixes

  • Grouping subcommands and commands (823a48e)

6.1.2 - (2023-08-29)

Refactor

  • Update types for nest version (d9d1578)

6.1.0 - (2023-08-21)

Refactor

  • Rename file with module definition (cb80c95)
  • Options metadata keys (854259a)
  • Explorer use not deprecated methods (1cfcd0d)
  • text-commands: Use reflector decorator (4288fed)
  • modals: Use reflector decorator (58f287a)
  • message-components: Use reflector decorator (7b6fc67)
  • listeners: Use reflector decorator (eef900d)
  • slash-commands: Use reflector decorator (11ed8c1)
  • context-menus: Use reflector decorator (4b41186)

6.0.0 - (2023-07-22)

Bug Fixes

  • Add error stack for log (3f29fa0)

Refactor

  • Make life cycle methods as private (b758b8a)
  • Make cached discovery data as public (fc180b9)
    • BREAKING CHANGE: .getCommands() methods removed
  • Remove deprecated interfaces, decorators and comments (8a72279)
    • BREAKING CHANGE: @Values and @SelectMenu removed
    • Refs: #515
  • Use typeguards from djs (c71cdd4)

Testing

5.9.0 - (2023-07-22)

Features

  • Add webhook events (#827) (ef23133)
  • Add get methods and use collection instead of maps (8a45056)

Refactor

  • Use target type from deconstruct (4f1e6bd)

Styling

  • Remove unused imports (ab1c420)
  • Use curly brackets for switch-case (81ebbb0)

5.8.4 - (2023-05-10)

Bug Fixes

  • Register commands to guild (7f215de)

5.8.3 - (2023-05-10)

Bug Fixes

  • Skip registering global when commands empty (9925b02)

5.8.1 - (2023-05-10)

Bug Fixes

  • Allow register command when getting error (f872895)

5.8.0 - (2023-04-25)

Features

  • Add methods for discovery #710 (783bb98)

Refactor

5.7.3 - (2023-04-17)

Refactor

  • Export explorer and another providers (d1d385d)

5.7.1 - (2023-04-13)

Refactor

  • Split global commands to all command (cace782)

Styling

5.7.0 - (2023-04-13)

Features

  • Add commands service methods for get commands (34a58f7)

5.6.1 - (2023-04-13)

Refactor

  • Rename guild audit logs event names (af91ac7)

5.6.0 - (2023-04-13)

Refactor

  • Update position of switch-case (dd63a25)

5.5.4 - (2023-04-03)

Bug Fixes

  • Add tsconfig for build and tests (2abef6c)

5.5.3 - (2023-04-01)

Testing

5.5.0 - (2023-03-09)

Bug Fixes

Features

Styling

5.4.8 - (2023-02-28)

Features

  • Add configurable module class (8af0f0d)

Styling

5.4.7 - (2023-02-28)

Bug Fixes

Styling

5.4.6 - (2023-02-26)

Features

  • Add warnings for duplicate registrations (#635) (b8596c8)

5.4.5 - (2023-02-08)

Bug Fixes

  • Select menu specs (#563) (769f08b)

5.4.0 - (2022-11-29)

Refactor

5.3.1 - (2022-11-26)

Features

  • Target decorators for message, user, member (47ccc2a)

5.3.0 - (2022-09-17)

Features

  • modal: Add dynamic matching (#385) (96a0c8f)

5.2.0 - (2022-08-11)

Features

  • Add get guilds method and guilds property (#352) (487caf2)

5.1.0 - (2022-07-31)

Bug Fixes

  • Usage without data parameter for ComponentParam (8c7ce11)

Features

  • Support dynamic matching for components (1b470b3)

5.0.1 - (2022-07-17)

Bug Fixes

  • Types for guild features lmao (d6f3727)
  • Change SlashCommandContext type (3d111da)
  • Change autocomplete type, tysm djs :) (a1d1400)
  • Remove update topic event (82403a4)
  • Remove update topic event (061470c)
  • Change description localizations property (d20d658)
  • Context and event interfaces (60b7002)
  • Add check for subcommands (7b3a07a)
  • Remove locals due memory leak (6857e01)
  • Inherited arguments (a4a74f3)
  • Types (3196848)
  • Remove rest provider (b24948e)

Documentation

  • Add git cliff for changelog (a1e8168)

Features

  • Support last breaking changes from djs (6442ff3)
  • Add error for registering subcommands w/o root command (3111de3)
  • Target decorator for context menus (044c701)
  • Support subcommands (5d23173)
  • Support last 14 version djs (7a58e06)
  • Add nsfw property (8179940)
  • Discordjs 14, modals, attachment option (6dfbe8d)

Refactor

  • Make autocomplete as interceptor (80c9f0b)
  • Change explorer service template and name (369f7cc)
  • Explorer templates (aa0ea19)
  • Remove custom function from explorer (d7a4121)
  • Use discord.js imports (85121f7)
  • Change flow for commands and discovery, support permissions v2 (c3dea7e)
  • Change slash command interface and decorator to object (bd0853b)
  • Change interfaces (05b8079)
  • Change flow and folder structure (3e2edc0)
  • Use object instead inline for context menus (0b27dca)
  • Change decorators type (1f7a48d)
  • Some improvements (4ac637d)
  • Remove cooldown guard, use @nestjs/throttle! (c57a237)

Styling

Testing

  • Getting context menu data from @Options (e3d9181)
  • Remove old decorators (15eb501)
  • Remove discovery from text command (d1588a6)
  • Change flow and add message-component spec (1eabdbe)
  • Wtf (8c3824b)
  • Change intents for client (e1b1797)
  • Change text command inline to object (85980a7)
  • Make global guilds (c612b45)