Commands not respecting cooldown preconditions

import { Command, RegisterSubCommand } from '@kaname-png/plugin-subcommands-advanced';
import { BucketScope } from '@sapphire/framework';

@RegisterSubCommand('legacy', (builder) =>
builder
.setName('raidrequest')
.setDescription("Mentions the raid request role.")
.addStringOption((option) =>
option
.setName("group")
.setDescription("The group requesting a raid.")
.setRequired(true)
),
)
export class UserCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
cooldownDelay: 600_000, // 10 minutes
cooldownScope: BucketScope.Global,
});
}
public override async chatInputRun(interaction: Command.ChatInputInteraction<'cached'>) {
. . .
}
}
import { Command, RegisterSubCommand } from '@kaname-png/plugin-subcommands-advanced';
import { BucketScope } from '@sapphire/framework';

@RegisterSubCommand('legacy', (builder) =>
builder
.setName('raidrequest')
.setDescription("Mentions the raid request role.")
.addStringOption((option) =>
option
.setName("group")
.setDescription("The group requesting a raid.")
.setRequired(true)
),
)
export class UserCommand extends Command {
public constructor(context: Command.Context) {
super(context, {
cooldownDelay: 600_000, // 10 minutes
cooldownScope: BucketScope.Global,
});
}
public override async chatInputRun(interaction: Command.ChatInputInteraction<'cached'>) {
. . .
}
}
I'm trying to make a command only run once every 10 mins globally, but it seems to just run anyway. @sapphire/framework v4.7.0
35 Replies
Favna
Favna8mo ago
@! naeko.moe is that a proper impl of your plugin? could it be conflicting in preconditions?
Sawako
Sawako8mo ago
pepeThink need to test
disclosuure
disclosuure8mo ago
In v2.3.0 of @kaname-png/plugin-subcommands-advanced btw (latest)
Favna
Favna8mo ago
@! naeko.moe any updates?
Sawako
Sawako8mo ago
Today
Favna
Favna8mo ago
@! naeko.moe
disclosuure
disclosuure8mo ago
i did get it working days ago with a custom cooldown but its still worth looking into
Sawako
Sawako8mo ago
It's weird that it doesn't work because what I do is grab all the preconditions of the command and then run the test whether they pass or not https://github.com/sawa-ko/neko-plugins/blob/main/packages/subcommands-advanced/src/lib/utils/const.ts#L36-L49 According to this line of code, the cooldown precondition is registered in the preconditions option of the command, which option is the one I read in my plugin https://github.com/sapphiredev/framework/blob/main/src/lib/structures/Command.ts#L434-L437pepeThink try new version 2.4.0
Xeno™
Xeno™8mo ago
does the latest version adds support for message based sub commands?
Favna
Favna8mo ago
it doesnt, it only switches preconditions to the preconditions provided by the base @sapphire/plugin-subcommands so if you want message based sub commands you'll have to stick to the base plugin and forego decorators granted there isn't much advantage to using the advanced plugin for message based subcommands because message based subcommands do not need to be registered at the discord api
Xeno™
Xeno™8mo ago
Uh i see, the default plugin for subcommands is pretty great anyways
Favna
Favna8mo ago
and having
subcommands: [
{
name: 'add',
messageRun: 'messageAdd'
}
]
subcommands: [
{
name: 'add',
messageRun: 'messageAdd'
}
]
isn't much config either
Xeno™
Xeno™8mo ago
would be better if i could have multiple decorators for each subcommand having the same attributes as the Command.Options
Favna
Favna8mo ago
the only thing you might be missing is description but you can chuck that into detailedDescription already anyway
Xeno™
Xeno™8mo ago
So is it possible to have seperate cooldowns for each subcommand?
Favna
Favna8mo ago
yes that was added with subcommand specific preconditions months ago
Xeno™
Xeno™8mo ago
Wait what?, I haven't updated but can you provide me with a example? because my typings isn't allowing me to (event after the update)
Favna
Favna8mo ago
it was added in 4.1.0 on 2023-08-21
Xeno™
Xeno™8mo ago
oh alr let me check Oh i see, but those are preconditions and definitely possible to have seperate cooldowns with the precondition approach, but then we would still need to create our own Preconditions right
Favna
Favna8mo ago
wdym
Xeno™
Xeno™8mo ago
I saw the pr, it only adds the support for preconditions only right, i am talking abt these options https://www.sapphirejs.dev/docs/Documentation/api-framework/interfaces/CommandOptions#cooldowndelay
Sapphire Framework
Interface: CommandOptions | Sapphire
The Command options.
Favna
Favna8mo ago
cooldowns are also preconditions the only thing missing are the shortcut options. that you linked but you can still add the precondition yourself
Xeno™
Xeno™8mo ago
and how do i configure them? precondition resolvables doesn't take objects right?
Favna
Favna8mo ago
they do
Favna
Favna8mo ago
Sapphire Framework
Interface: PreconditionSingleResolvableDetails | Sapphire
Defines the detailed options for the PreconditionContainerSingle, where both the PreconditionContext and the
Sapphire Framework
@sapphire/framework | Sapphire
Namespaces
Xeno™
Xeno™8mo ago
oh yeah just found out
No description
Xeno™
Xeno™8mo ago
thanks a lot It'll be very helpful thanks again
Favna
Favna8mo ago
{
name: 'show',
chatInputRun: 'configShow',
default: true,
preconditions: [{ name: CommandPreConditions.Cooldown, context: { scope: BucketScope.User, limit: 5, delay: 5 } }]
},
{
name: 'show',
chatInputRun: 'configShow',
default: true,
preconditions: [{ name: CommandPreConditions.Cooldown, context: { scope: BucketScope.User, limit: 5, delay: 5 } }]
},
Xeno™
Xeno™8mo ago
❤️
Favna
Favna8mo ago
GitHub
feat(subcommands): add support for all remaining precondition short...
No idea why I didn't just do this right away when I added runIn
Xeno™
Xeno™8mo ago
yeah lmfao, i was struggling with this a minute ago thanks a lot
Sawako
Sawako8mo ago
thonk
Favna
Favna8mo ago
am I giving you extra work again omegalul ? @Xeno™ seeing as you dont have the Ping Me For Announcements role you may have missed #Announcements so it's been released. Going to unfollow this thread now.
Xeno™
Xeno™8mo ago
Oh ok alr