Necord

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

README

necord


About


This package uses the best of the NodeJS 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 fast and easy way for 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 16.6.0 or newer is required.

  1. ```bash
  2. $ npm i necord discord.js
  3. $ yarn add necord discord.js
  4. $ pnpm add necord discord.js
  5. ```

Usage


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

  1. ```typescript
  2. import { NecordModule } from 'necord';
  3. import { Module } from '@nestjs/common';

  4. @Module({
  5.     imports: [
  6.         NecordModule.forRoot({
  7.             token: 'DISCORD_BOT_TOKEN',
  8.             intents: ['Guilds', 'GuildMessages', 'DirectMessages']
  9.         })
  10.     ],
  11.     providers: []
  12. })
  13. export class AppModule {
  14. }
  15. ```

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

  1. ```typescript
  2. import { Injectable, Logger } from '@nestjs/common';
  3. import { Context, On, Once, ContextOf } from 'necord';
  4. import { Client } from 'discord.js';

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

  8.     public constructor(private readonly client: Client) {
  9.     }
  10.     
  11.     @Once('ready')
  12.     public onReady(@Context() [client]: ContextOf<'ready'>) {
  13.         this.logger.log(`Bot logged in as ${client.user.username}`);
  14.     }

  15.     @On('warn')
  16.     public onWarn(@Context() [message]: ContextOf<'warn'>) {
  17.         this.logger.warn(message);
  18.     }
  19. }
  20. ```

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


Twitter - @SocketSomeone

License