Home

Awesome

<div align="center"> <h1> <a href="#"><img src="https://necord.org/img/logo.png" alt ="Necord Logo"></a> </h1> 🤖 A module for creating <b><a href="https://discord.com/">Discord</a> bots</b> using <a href="https://nestjs.com">NestJS</a>, based on <a href="https://discord.js.org/">Discord.js</a> <br/><br/> <a href="https://necord.org">Documentation ✨</a> &emsp; <a href="https://github.com/necordjs/necord">Source code 🪡</a> &emsp; <a href="https://github.com/necordjs/samples">Examples 🛠️</a> &emsp; <a href="https://discord.gg/mcBYvMTnwP">Community 💬</a> </div> <br/> <p align="center"> <a href='https://img.shields.io/npm/v/necord'><img src="https://img.shields.io/npm/v/necord" alt="NPM Version" /></a> <a href='https://img.shields.io/npm/l/necord'><img src="https://img.shields.io/npm/l/necord" alt="NPM License" /></a> <a href='https://img.shields.io/npm/dm/necord'><img src="https://img.shields.io/npm/dm/necord" alt="NPM Downloads" /></a> <a href='https://img.shields.io/github/last-commit/necordjs/necord'><img src="https://img.shields.io/github/last-commit/SocketSomeone/necord" alt="Last commit" /></a> </p>

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

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('ready')
    public onReady(@Context() [client]: ContextOf<'ready'>) {
        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:

Backers

<a href="https://opencollective.com/necord" target="_blank"><img src="https://opencollective.com/necord/backers.svg?width=1000"></a>

Stay in touch

License

MIT © Alexey Filippov