# nestjs-discord-transporter

> Discord event listener for Nestjs

Latest version **0.1.5** (published 2023-05-01) · MIT license · 0 weekly downloads

## Install

```sh
npm install nestjs-discord-transporter
pnpm add nestjs-discord-transporter
yarn add nestjs-discord-transporter
bun add nestjs-discord-transporter
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.5 |
| Published | 2023-05-01 |
| First published | 2023-04-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 29.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Francisco Damião Terto |
| Maintainers | damiaot |
| Keywords | discord, nestjs, nestjs-transporter |

## Links

- npm: https://www.npmjs.com/package/nestjs-discord-transporter
- Repository: https://github.com/damiaoterto/nestjs-discord-transporter
- Homepage: https://github.com/damiaoterto/nestjs-discord-transporter#readme
- Issues: https://github.com/damiaoterto/nestjs-discord-transporter/issues
- npm.io page: https://npm.io/package/nestjs-discord-transporter

## Recent versions

- 0.1.5 (latest) — 2023-05-01
- 0.1.4 — 2023-04-29
- 0.1.3 — 2023-04-25

## README

[![damiaoterto - nestjs-discord-transporter](https://img.shields.io/static/v1?label=damiaoterto&message=nestjs-discord-transporter&color=green&logo=github)](https://github.com/damiaoterto/nestjs-discord-transporter "Go to GitHub repo")
[![GitHub tag](https://img.shields.io/github/tag/damiaoterto/nestjs-discord-transporter?include_prereleases=&sort=semver&color=green)](https://github.com/damiaoterto/nestjs-discord-transporter/releases/)
[![License](https://img.shields.io/badge/License-MIT-green)](#license)
[![stars - nestjs-discord-transporter](https://img.shields.io/github/stars/damiaoterto/nestjs-discord-transporter?style=social)](https://github.com/damiaoterto/nestjs-discord-transporter)
[![forks - nestjs-discord-transporter](https://img.shields.io/github/forks/damiaoterto/nestjs-discord-transporter?style=social)](https://github.com/damiaoterto/nestjs-discord-transporter)

# Description

A Discord event listener for Nest.js based on [discord.js](https://discord.js.org/) 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:

```typescript
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](https://discord.com/developers/applications)  |
| intents  | false | The bot intents [access docs here](https://discordjs.guide/popular-topics/intents.html#privileged-intents)  |
| partials  | false | The bot partials [access docs here](https://discordjs.guide/popular-topics/partials.html#enabling-partials)  |
| 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**

```typescript
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](https://discordjs.guide/creating-your-bot/event-handling.html#individual-event-files)

# Dependencies

``discord.js: ``[Documentation](https://discordjs.guide)

``Nest.js: ``[Documentation](https://docs.nestjs.com/microservices/basics)

---
_Source: https://npm.io/package/nestjs-discord-transporter · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
