owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!

Home Page:https://owencalvin.github.io/discord.ts/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Utilizing @Command causes an UnhandledPromiseRejectionWarning

russjr08 opened this issue · comments

Version 4.0.8
(discord.js 12.3.1)

Utilizing the given tsconfig.json from the README

Not sure what exactly is causing this exception I'm running into... However whenever I add a function with a @Command decorator, I appear to lose functionality of my @On event as well. Whenever the bot picks up a message, the following is thrown into stdout:

(node:4477) UnhandledPromiseRejectionWarning: TypeError: (intermediate value).flatMap is not a function
    at Promise.all.events.map (/home/russjr08/discord-bot/node_modules/@typeit/src/logic/metadatas/MetadataStorage.ts:155:14)
    at process._tickCallback (internal/process/next_tick.js:68:7)
(node:4477) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:4477) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Here is my class that is being used with @Discord

import { Discord, Command, CommandMessage, On, ArgsOf } from "@typeit/discord";

@Discord("&")
abstract class Bot {
    @On("message")
    private onMessage([message]: ArgsOf<"message">) {
        console.log(`Received message from ${message.author.username} with contents ${message.content}`)
    }

    @Command("ping")
    private onPingRequest(message: CommandMessage) {
        console.log("ping received!")
    }
}

If I comment out the on message event, I still get the exception. If I even send a message that does not have the & prefix, the exception is still printed. If I comment out the @Command event, then all is fine.

I'll definitely admit I am newer to TypeScript, so it could be something I am doing wrong myself but... I've stuck with pretty much everything from README at this point.

Away from my computer but I'm pretty sure this is actually due to an older version of Node.

Closing for now, and will reopen if that's not the case after testing with nodeenv.

commented

I have the same issue, with the following versions:

node: 10.19.0
npm: 6.14.4
typeit/discord: 4.0.10
discord.js: 13.0.1

@lukasbm update your node.js to v16 and discord.ts is not maintained for v13 of discord.js.

I suggest you should upgrade to discord.ts (discordx), discordx is improved version of this package.