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-transporter

v0.1.5

Published

Discord event listener for Nestjs

Downloads

2

Readme

damiaoterto - nestjs-discord-transporter GitHub tag License stars - nestjs-discord-transporter forks - nestjs-discord-transporter

Description

A Discord event listener for Nest.js based on discord.js package.

Installation

Warning Assuming you have installed the @nestjs/microservices package.

Using NPM:

npm install discord.js nestjs-discord-transporter

Using Yarn:

yarn add discord.js nestjs-discord-transporter

Quick Start

Overview

To use the Discord transporter, pass the following options object to the createMicroservice() method on main.ts file:

import { NestFactory } from '@nestjs/core';
import { MicroserviceOptions } from '@nestjs/microservices';
import { DiscordTransporter } from 'nestjs-discord-transporter';
import { AppModule } from './app.module';

async function bootstrap() {
  const app = await NestFactory.createMicroservice<MicroserviceOptions>(
    AppModule,
    {
      strategy: new DiscordTransporter({
        token: '<you-token>', // or set the environment var DISCORD_TOKEN
        intents: [], // optional param
        partials: [], // optional param
        prefix: 'command:', // optional if receive commands
      }),
    },
  );
  await app.listen();
}
bootstrap();

Transporter options

| Param | Required | Description | ------------- | ------------- | ------------- | | token | true | The discord access token access here | | intents | false | The bot intents access docs here | | partials | false | The bot partials access docs here | | prefix | false | if receive specific commands |

Request-response

To create a message handler based on the request-response paradigm use the @MessagePattern() decorator, which is imported from the @nestjs/microservices package. This decorator should be used only within the controller classes since they are the entry points for your application. Using them inside providers won't have any effect as they are simply ignored by Nest runtime.

app.controller.ts

import { Controller } from '@nestjs/common';
import { Message } from 'discord.js';
import { MessagePattern } from '@nestjs/microservices';
import { AppService } from './app.service';

@Controller()
export class AppController {
  constructor(private readonly appService: AppService) {}

  @MessagePattern('messageCreate')
  async getHello(message: Message) {
    message.channel.sendTyping();
    const response = await this.appService.handleMessage(message.content);
    message.channel.send(response);
  }
}

for more information on the message object click here

Dependencies

discord.js: Documentation

Nest.js: Documentation