fjodor-rybakov / discord-nestjs

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

discord-nestjs/packages/common/src/pipe/slash-command /slash-command.pipe.ts #1026

Closed MelvinCado closed 1 year ago

MelvinCado commented 1 year ago

Hello

Description

When i try to use my slashCommand with params, i have this error : this.metadataProvider.isDto is not a function This is exactly at the line https://github.com/fjodor-rybakov/discord-nestjs/tree/master/packages/common/src/pipe/slash-command:32 And i dont know why.

To Reproduce

  1. My class command :
    
    import { SlashCommandPipe } from '@discord-nestjs/common';
    import {
    Command,
    EventParams,
    Handler,
    InteractionEvent,
    } from '@discord-nestjs/core';
    import { Injectable } from '@nestjs/common';
    import { ClientEvents } from 'discord.js';
    import { StuffyDto } from '../dto/stuffy.dto';

@Command({ name: 'stuffy', description: 'Trouve ton stuff idéal.', }) @Injectable() export class StuffyCommand { @Handler() stuffy( @InteractionEvent(SlashCommandPipe) dto: StuffyDto, @EventParams() args: ClientEvents['interactionCreate'], ): string { console.log(dto, args);

return 'hello world';

} }


2. My class Dto : 
```js
import { Param } from '@discord-nestjs/core';
import { Choice } from '@discord-nestjs/core/dist/decorators/option/choice/choice.decorator';
import { ParamType } from '@discord-nestjs/core/dist/definitions/types/param.type';

enum Nade {
  FLASH = 'flash',
  SMOKE = 'smoke',
  MOLOTOV = 'molotov',
  GRENADE = 'grenade',
}

enum Map {
  DUST2 = 'dust2',
  INFERNO = 'inferno',
}

export class StuffyDto {
  @Param({
    name: 'carte',
    description: 'La carte souhaitée.',
    type: ParamType.STRING,
    required: true,
  })
  @Choice(Map)
  map: Map;

  @Param({
    name: 'grenade',
    description: 'La grenade souhaitée.',
    type: ParamType.STRING,
    required: true,
  })
  @Choice(Nade)
  nade: Nade;

  @Param({
    name: 'atterrissage',
    description: 'Le lieu d’atterrissage de la grenade.',
    type: ParamType.STRING,
    required: false,
  })
  end: string;
  @Param({
    name: 'depart',
    description: 'Le lieu du lancement de la grenade',
    type: ParamType.STRING,
    required: false,
  })
  start: string;
}

3: I use my command in discord with this params : carte: dust2, grenade: flash. I do a CTRL + Enter to use the bot and i have an error

  1. I have the following error in my terminal :
    [Nest] 2980  - 06/03/2023, 00:57:21   ERROR [ExceptionsHandler] this.metadataProvider.isDto is not a function
    TypeError: this.metadataProvider.isDto is not a function
    at SlashCommandPipe.transform (C:\wamp64\www\discord-bot-lotentick\node_modules\@discord-nestjs\common\src\pipe\slash-command\slash-command.pipe.ts:32:30)
    at C:\wamp64\www\discord-bot-lotentick\node_modules\@nestjs\core\pipes\pipes-consumer.js:16:33
    at processTicksAndRejections (node:internal/process/task_queues:96:5)

Can you fix this bug please ?

Regards

fjodor-rybakov commented 1 year ago

Hi! Make sure you have installed latest @discord-nestjs/core@5.3.3

MelvinCado commented 1 year ago

Ok, yes that's work ! I used @discord-nestjs/core@5.3.0 so i update the version and that's work. Thank you :) 👍