messageRun commands

I'm getting an issue and honestly, don't know what's wrong, i'm using the template generated by the CLI and everything runs fine, however, when i try preconditions on messageRun subcommands they just not work for some reason? they work on messageRun commands but not subcommands. For example, i'm trying the precondition that comes with the template
export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return OWNERS.includes(userId) ? this.ok() : this.error({ message: this.#message });
}
export class OwnerOnlyPrecondition extends AllFlowsPrecondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return OWNERS.includes(userId) ? this.ok() : this.error({ message: this.#message });
}
it works on chatInput Subcommands and Commands, but not on messageRun subcommands
aliases: ['cws'],
description: 'A basic command with some subcommands',
subcommands: [
{
name: 'add',
messageRun: 'messageAdd',
preconditions: ['OwnerOnlyPrecondition']
},
aliases: ['cws'],
description: 'A basic command with some subcommands',
subcommands: [
{
name: 'add',
messageRun: 'messageAdd',
preconditions: ['OwnerOnlyPrecondition']
},
2024-05-14 02:03:34 - DEBUG - [0] - command-with-subcommands arestosora[249600415040012309] tests server[1134593541172117544]
2024-05-14 02:03:34 - DEBUG - [0] - command-with-subcommands arestosora[249600415040012309] tests server[1134593541172117544]
the command is fired but the precondition does not return anything and the command does not return anything either.
Solution:
If I use sapphire new and then make only 2 edits: 1. Fill in .env 2. Add preconditions: ['OwnerOnly'] to src/commands/General/command-with-subcommands.ts then it does work...
No description
Jump to solution
2 Replies
Solution
Favna
Favna7mo ago
If I use sapphire new and then make only 2 edits: 1. Fill in .env 2. Add preconditions: ['OwnerOnly'] to src/commands/General/command-with-subcommands.ts then it does work Note that there is no reply from the bot at the bottom because no listener for SubcommandPluginEvents.MessageSubcommandDenied is included in the template, in case that's all that you're wondering about. A precondition works if the command doesn't execute, that's the whole point of a precondition after all. Considering that your file is seemingly called OwnerOnlyPrecondition as opposed to the default OwnerOnly, are you sure you didn't break anything along the way?
No description
dazx
dazxOP7mo ago
It was that i was missing the listener implementation for Message Subcommands, about the name i just renamed the precondition, thanks for the help!
Want results from more Discord servers?
Add your server