owengombas / discord.ts

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

Add brackets when calling empty Discord decorator #9

Closed phen0menon closed 4 years ago

phen0menon commented 4 years ago

Problem

When using the following code from the repository documentation:

import { Discord } from '@typeit/discord';

@Discord() // Decorate the class
abstract class AppDiscord {}

My application crashes with the following error:

\node_modules\@typeit\src\Decorators\Discord.ts:1
TypeError: Cannot read property 'importCommands' of undefined
    at \node_modules\@typeit\src\Decorators\Discord.ts:24:16
    at DecorateConstructor (\node_modules\reflect-metadata\Reflect.js:541:33)
    at Object.decorate (\node_modules\reflect-metadata\Reflect.js:130:24)
    at Object.__decorate (\node_modules\tslib\tslib.js:92:96)
    at Object.<anonymous> (\src\main.ts:9:22)
    at Generator.next (<anonymous>)

My tool configuration is:

Node v12.16.1
TypeScript 3.8.2
ts-node 8.9.1

Solution

According to Judge user from the discord channel, I fixed this by adding brackets in the parentheses when calling Discord decorator in this way:

import { Discord } from '@typeit/discord';

@Discord({}) // Decorate the class with brackets in parentheses
abstract class AppDiscord {}

Maybe it'll be useful for someone with the same versions of configuration tools.

owengombas commented 4 years ago

Thank's, for reporting this issue ! I applied this patch, you can now update the package (npm update, version 2.0.19) and remove the brackets. :)