fjodor-rybakov / discord-nestjs

👾 NestJS package for discord.js
MIT License
271 stars 49 forks source link

Nest can't resolve dependencies of the SlashCommandPipe #1153

Closed ArtemOsuskyi closed 10 months ago

ArtemOsuskyi commented 10 months ago

Describe the bug Starting an app causes Nest to throw an error Nest can't resolve dependencies of the SlashCommandPipe (?, __class_transformer_options__). Please make sure that the argument ReflectMetadataProvider at index [0] is available in the BotModule context. during startup. Using NestJS version from @discord-nestjs/schematics:application template (v10.0.0)

import { EventParams, Handler, IA, SubCommand } from '@discord-nestjs/core';
import { ClientEvents } from 'discord.js';

import { SlashCommandPipe } from '@discord-nestjs/common';
import { CreateQuestDto } from '../../dto/create-quest.dto';

@SubCommand({
  name: 'create',
  description: 'Plays a song',
})
export class QuestCreateSubCommand {
  @Handler()
  questCreate(
    @IA(SlashCommandPipe) createQuestDto: CreateQuestDto,
    @EventParams() args: ClientEvents['interactionCreate'],
  ): string {
    console.log(createQuestDto);
    console.log(args);

    return 'Quest created';
  }
}

Tried to do so far

To Reproduce Steps to reproduce the behavior:

  1. Pass @InteractionEvent(SlashCommandPipe) in any command params.
  2. Run npm run start:dev
fjodor-rybakov commented 10 months ago

Hi! Try to add DiscordModule.forFeature() to module imports

ArtemOsuskyi commented 10 months ago
import { DiscordModule } from '@discord-nestjs/core';
import { Module } from '@nestjs/common';

import { QuestCommand } from './commands/quest/quest.command';
import { QuestCreateSubCommand } from './commands/quest/quest-create.sub-command';
import { QuestClaimSubCommand } from './commands/quest/quest-claim.sub-command';

@Module({
  imports: [DiscordModule.forFeature()],
  providers: [QuestCommand, QuestCreateSubCommand, QuestClaimSubCommand],
})
export class BotModule {}

Here's the code for the module I use commands with, it doesn't start up even with imported DiscordModule.forFeature()

To avoid any further confusion, here's the app.module.ts:

import { Module } from '@nestjs/common';
import { DiscordModule } from '@discord-nestjs/core';
import { ConfigModule, ConfigService } from '@nestjs/config';
import { GatewayIntentBits } from 'discord.js';
import { BotModule } from './bot/bot.module';

@Module({
  imports: [
    ConfigModule.forRoot({
      isGlobal: true,
    }),
    DiscordModule.forRootAsync({
      imports: [ConfigModule],
      inject: [ConfigService],
      useFactory: (configService: ConfigService) => {
        return {
          token: configService.get<string>('DISCORD_BOT_TOKEN'),
          discordClientOptions: {
            intents: [
              GatewayIntentBits.Guilds,
              GatewayIntentBits.MessageContent,
              GatewayIntentBits.GuildMembers,
              GatewayIntentBits.GuildMessages,
            ],
          },
        };
      },
    }),
    BotModule,
  ],
})
export class AppModule {}
fjodor-rybakov commented 10 months ago

Check that you only have 1 version of the library installed in the repository

ArtemOsuskyi commented 10 months ago

Reinstalled @discord-nestjs/core and @discord-nestjs/common and issue got fixed. Thank you, sorry for the inconvenience!