owengombas / discord.ts

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

commandName bug #16

Closed samarmeena closed 3 years ago

samarmeena commented 4 years ago

command.commandName return last command name inside a class. This happens when you define multiple commands under single class using decorator. Below this the example code of this issue

export abstract class Fun {

    @Command("cats")
    async catfaces(command: CommandMessage, client: Client) {
    }

    @Command("joke")
    async joke(command: CommandMessage, client: Client) {
    }

    @Command("qr")
    async qr(command: CommandMessage, client: Client) {
    }

    @Command("comic")
    async comic(command: CommandMessage, client: Client) {
    }

}

it returns comic for all commandName for defined commands in this class such as for qr it will return commandName comic.

https://discordapp.com/channels/693401527494377482/693401527494377485/718265975283122216

tonyeung commented 4 years ago

Not sure if this is related.. but in a guard, the message.commandName always returns the first command called... issue can be replicated with this throttle guard outlined below.

For the full project, see my repo at https://github.com/tonyeung/statics.bot. Please note that the throttle guard I have in the project has a working version where I pass the command name into the guard as a workaround.

import { ArgsOf, GuardFunction } from "@typeit/discord";

export const Throttle = (): GuardFunction => {    
    const guard: GuardFunction = async ([message]: ArgsOf<"commandMessage">, client, next) => {
        console.log("inside throttle, called " + message.commandName);
        console.log("commands called: " + process.env.commands);

        if (process.env.commands.indexOf(message.commandName) == -1) {
            console.log(message.commandName + " not found");
            process.env.commands += message.commandName;
            await next();
        }
        else {
            console.log(message.commandName + " found");
            message.reply("already executed command");
        }        
    };

    return guard;
};
samarmeena commented 3 years ago

Closed

Reason: package is not maintained regularly.