owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!
https://owencalvin.github.io/discord.ts/
325 stars 40 forks source link

Info and Description decorators not working on commands #43

Closed ghost closed 3 years ago

ghost commented 3 years ago
// src/bot/bot.ts
import { ArgsOf, Discord, Client } from "@typeit/discord";
import config from "../core/config";
import * as Path from 'path';

@Discord(config.bot.prefix, {
  import: [
    Path.join(__dirname, "commands", "*/*command.ts")
  ]
})
export class Bot extends Client {}
// src/bot/commands/help.command.ts
import { Command, CommandMessage, Client, Description, Infos } from "@typeit/discord";

export abstract class HelpCommand {
  @Description('Show available commands')
  @Infos({ type: 'help' })
  @Command('help')
  async showCommands(message: CommandMessage) {
    const commands = Client.getCommands();

    const commandNames = [];
    commands.forEach(command => {
      commandNames.push(command.commandName);
    })

    message.channel.send(commandNames);
  }
}

However, as you can see, it doesnt really add any of the metadata to the command

//console.log(Client.getCommands())
[
  {
    description: undefined,
    infos: {},
    argsRules: [ [AsyncFunction (anonymous)] ],
    prefix: '\\.',
    commandName: 'help'
  }
]
ghost commented 3 years ago

Solution found: Order of decorators matter:

  @Command('help')
  @Infos({ type: 'help' })
  @Description('Show available commands')

works, Command has to come before infos, which has to come before description.

Thank you, TheMartonfi#5712