npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nestjs-discord-framework

v2.2.1

Published

Simple Framework to help integrate Discord bots with Nestjs Servers

Downloads

13

Readme

NestJS Bot Platform

Installation

$ npm i --save nestjs-discord-framework

Usage

Version 1.0.0 is not supported and should be upgraded to v2.x immediately.

To use the Framework just import the BotModule in the root AppModule and supply the options. The forRoot() method supports all the Discord.JS ClientOptions. In addition there are some extra configuration properties described below:

| Key | Description | | -------- | ----------------------------- | | token | The Discord Bot accesstoken | | prefix | The command prefix (optional) |

BotModule.forRoot(options:BotOptions),

Asynchronous loading of the options is also possible. One approach is to use a factory function:

BotModule.forRootAsync({
  useFactory: (): BotOptions => ({
    token: 'your-token',
    prefix: '!',
  }),
});

The factory behaves like any other asynchronous provider (e.g., it can be async and it's able to inject dependencies through inject):

BotModule.forRootAsync({
  imports: [ConfigModule],
  useFactory: (configService: ConfigService): BotOptions => ({
    token: configService.get('bot-token'),
    prefix: configService.get('bot-prefix'),
  }),
  inject: [ConfigService],
});

Alternatively, you can use the useClass or useExisting syntax:

BotModule.forRootAsync({
  useClass: BotConfigService,
});

Registering Events

Make sure that all classes using the @BotEvent() decorator are registered as providers

You can subscribe to Discord events by annotating a public method of a provider with the @BotEvent(event:string) Decorator. The Parameter is the name of the event you want to listen to. You can find a full list of Events here

@Injectable()
export class EventHandler {
  @BotEvent('guildMemberAdd')
  onGuildMemberAdd(...args: any[]): void {}
}

Registering Commands

Make sure that all classes using the @BotCommand() decorator are registered as providers

To register a command annotate a public provider method with the @BotCommand(name:string) Decorator. The Parameter is the first index of the message content split by " " without the prefix.

export class HelpCommand {
  @BotCommand('help')
  help(...args: any[]): void {}
}

Client-/Instance-Injection

You can inject the Client and the instance (BotInstance) into your providers and controllers. Simply use the @InjectBotClient() and @InjectBotInstance() Decorators in the constructor:

export class InjectClient {
  constructor(@InjectBotClient() private client) {}
}

export class InjectInstance {
  constructor(@InjectBotInstance() private instance) {}
}