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
Favna15mo ago
@! naeko.moe is that a proper impl of your plugin? could it be conflicting in preconditions?
Sawako
Sawako15mo ago
pepeThink need to test
disclosuure
disclosuureOP15mo ago
In v2.3.0 of @kaname-png/plugin-subcommands-advanced btw (latest)
Favna
Favna15mo ago
@! naeko.moe any updates?
Sawako
Sawako15mo ago
Today
Favna
Favna15mo ago
@! naeko.moe
disclosuure
disclosuureOP15mo ago
i did get it working days ago with a custom cooldown but its still worth looking into
Sawako
Sawako15mo 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
Xeno15mo ago
does the latest version adds support for message based sub commands?
Favna
Favna15mo 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
Xeno15mo ago
Uh i see, the default plugin for subcommands is pretty great anyways
Favna
Favna15mo ago
and having
subcommands: [
{
name: 'add',
messageRun: 'messageAdd'
}
]
subcommands: [
{
name: 'add',
messageRun: 'messageAdd'
}
]
isn't much config either
Xeno
Xeno15mo ago
would be better if i could have multiple decorators for each subcommand having the same attributes as the Command.Options
Favna
Favna15mo ago
the only thing you might be missing is description but you can chuck that into detailedDescription already anyway
Xeno
Xeno15mo ago
So is it possible to have seperate cooldowns for each subcommand?
Favna
Favna15mo ago
yes that was added with subcommand specific preconditions months ago
Xeno
Xeno15mo 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
Favna15mo ago
it was added in 4.1.0 on 2023-08-21
Xeno
Xeno15mo 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
Favna15mo ago
wdym
Xeno
Xeno15mo 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
Favna15mo 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
Xeno15mo ago
and how do i configure them? precondition resolvables doesn't take objects right?
Favna
Favna15mo ago
they do
Favna
Favna15mo 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
Xeno15mo ago
oh yeah just found out
No description
Xeno
Xeno15mo ago
thanks a lot It'll be very helpful thanks again
Favna
Favna15mo 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
Xeno15mo ago
❤️
Favna
Favna15mo 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
Xeno15mo ago
yeah lmfao, i was struggling with this a minute ago thanks a lot
Sawako
Sawako15mo ago
thonk
Favna
Favna15mo 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
Xeno15mo ago
Oh ok alr
Want results from more Discord servers?
Add your server