Code Monkey home page Code Monkey logo

necord's Introduction

Necord Logo

๐Ÿค– A module for creating Discord bots using NestJS, based on Discord.js

Documentation โœจ โ€ƒ Source code ๐Ÿชก โ€ƒ Examples ๐Ÿ› ๏ธ โ€ƒ Community ๐Ÿ’ฌ

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.

$ 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 { Intents } from 'discord.js';

@Module({
    imports: [
        NecordModule.forRoot({
            token: 'DISCORD_BOT_TOKEN',
            intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.DIRECT_MESSAGES]
        })
    ],
    providers: []
})
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:

  • 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.

Stay in touch

License

MIT ยฉ Alexey Filippov

necord's People

Contributors

antonygarand avatar dependabot[bot] avatar eliasgcf avatar renovate[bot] avatar socketsomeone avatar wolffparkinson avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.