Closed LiquidMonkey closed 3 years ago
should be able to use
@CommandNotFound()
async notFound(message: Message): any {
console.error('command not found', message);
}
+1 this is definitely a bug somehow, as it's not working for me, too.
Not doing anything fancy with it like OP is, either.
@CommandNotFound()
async commandNotFound(message: CommandMessage): Promise<void> {
await message.channel.send(
"I'm sorry, I don't understand! Please type '!help' for a list of " +
'commands I understand.'
);
}
+1 this is definitely a bug somehow, as it's not working for me, too.
Not doing anything fancy with it like OP is, either.
@CommandNotFound() async commandNotFound(message: CommandMessage): Promise<void> { await message.channel.send( "I'm sorry, I don't understand! Please type '!help' for a list of " + 'commands I understand.' ); }
whats your console output when this happens?
I just used your code snippet and it worked @somarkoe see image above
I'll be closing this issue soon the issue @LiquidMonkey has is they are using ArgsOf in the notFound method ArgsOf is for discord events and command message only
and because the message is not a command the ArgsOf is not applicable here
@CommandNotFound()
@Guard(ShouldRespond)
async notFound(message: Message): Promise<void> {
// Do something when a command is not found
message.reply("Command not found check `--list for commands`");
}
will fix their issue
whats your console output when this happens?
There's absolutely no console output when I type a command that isn't registered with the bot :( It just ignores it entirely.
@somarkoe What does your project set up look like? Is this in a class that has @Discord on it?
Here's my setup:
// bot.ts
export class Bot {
private _client: Client;
constructor() {
this._client = new Client({
classes: [AdminCommands, GeneralCommands],
silent: false,
variablesChar: ':',
});
}
...
}
// admin_commands.ts
/**
* Commands only admins have access to.
*/
@Discord('!')
export abstract class AdminCommands {
...
}
// general_commands.ts
/**
* General commands available to everybody.
*/
@Discord('!')
export abstract class GeneralCommands {
...
/**
* Sends a message to the channel when a command is executed that isn't
* defined.
*/
@CommandNotFound()
async commandNotFound(message: CommandMessage): Promise<void> {
await message.channel.send(
"I'm sorry, I don't understand! Please type '!help' for a list of " +
'commands I understand.'
);
}
}
All commands defined within both GeneralCommands
and AdminCommands
work.
curious to see if putting the path instead of the imported classes would do anything
kinda like here https://github.com/OwenCalvin/discord.ts/blob/master/starter-projects/simple-bot/SimpleBot/src/Main.ts thats how it is here too https://github.com/OwenCalvin/discord.ts
maybe?
Thank you for this great framework :D its very pleasant to work with.
Unfortunately I can't seem to manage to get the CommandNotFound decorator to work. Can you help me?
I have the following code for my commandnotfound function.
the ShouldRespond guard looks like this:
With the above code I run into this issue where whenever this event would fire it gives me this error in the console.
(node:17460) TypeError: undefined is not a function at CommandNotFoundEvent.notFound (C:**\build\src\Event\CommandNotFound.js:8:19)
It throws this error 2 times with different errors: UnhandledPromiseRejectionWarning: TypeError
and also gives a DepreciationWarning: Unhandled promise rejections are deprecated. In the future, promis rejections that are not handled will terminate the node.js process
Any help would be highly appreciated.