Luxizzle / discord-nestjs

👾 NestJS package for discord.js

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Nest Logo

A progressive Node.js framework for building efficient and scalable server-side applications, heavily inspired by Angular.

Package License

👨🏻‍💻 Installation

$ npm install @discord-nestjs/core discord.js

Or via yarn

$ yarn add @discord-nestjs/core discord.js

🧾 Description

NestJS package for discord.js

This monorepo consists of several packages.

❓ Answers on questions

The bot starts up, but the slash commands and events do not work

Click to expand

Check your intent is passed to the discordClientOptions of the module. More info

I created DTO and added TransformPipe, but when I receive response to the command, the DTO fields are missing

Click to expand

Check what your target version from tsconfig.json. Now is the minimal version of ESNext. Also check that the Palyoad and UsePipes decorators are imported from @discord-nestjs/core.

How to inject dependencies into your command, pipe, guard or filter

Click to expand

At the moment, this is only possible if the module is declared using forRootAsync. First, you need to declare a separate module and set the necessary providers, as well as set them for export.

import { PlayService } from './play.serivce';
import { Module } from '@nestjs/common';

@Module({
  providers: [PlayService],
  exports: [PlayService],
})
export class PlayModule {}

And then add this module to the DiscordModule imports

import { PlayModule } from './services/play.module';
import { DiscordModule } from '@discord-nestjs/core';
import { Module } from '@nestjs/common';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { Intents, Message } from 'discord.js';

@Module({
  imports: [
    DiscordModule.forRootAsync({
      imports: [ConfigModule, PlayModule],
      useFactory: (configService: ConfigService) => ({
        token: configService.get('TOKEN'),
        commands: ['**/*.command.js'],
        discordClientOptions: {
          intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES],
        },
        registerCommandOptions: [
          {
            forGuild: configService.get('GUILD_ID_WITH_COMMANDS'),
            allowFactory: (message: Message) =>
              !message.author.bot && message.content === '!deploy',
          },
        ],
      }),
      inject: [ConfigService],
    }),
  ],
})
export class BotModule {}

And then you can inject your dependencies

import { PlayService } from '../services/play.serivce';
import { Command } from '@discord-nestjs/core';
import { DiscordCommand } from '@discord-nestjs/core/src';
import { CommandInteraction } from 'discord.js';

@Command({
  name: 'play',
  description: 'Plays a song',
})
export class PlayCommand implements DiscordCommand {
  constructor(private readonly playService: PlayService) {}

  handler(interaction: CommandInteraction): string {
    return this.playService.play();
  }
}

Any questions or suggestions? Discord Федок#3051

About

👾 NestJS package for discord.js

License:MIT License


Languages

Language:TypeScript 99.3%Language:JavaScript 0.6%Language:Shell 0.1%