Remove Cooldown for a Subcommand while using an external derived class
I get that there are ways to delete cooldowns in actual
Commands, and other ways. Even ways to do the same thing with anything extending Subcommand. But I have a problem here, I'm using an external class to keep my code modular and clean, but this raises a problem for me.
I can't seem to delete cooldowns from the WeakMap with this setup, and I don't want to have to make the base class extend Subcommand if I don't need to since it's gonna break a lot of things, mainly with how I'm using them (I'd have to pass some extra stuff into each subcommand, which would be less than good). Is there any other ways of doing what I'm wanting to do here? I haven't found any sort of guide on this particular topic, so... If this is a stupid question, I apologize.
Also, if I am missing anything in here, let me know. I will happily try to get as much help as I can here.
Information
- Bun version: 1.3.1
- Sapphire version: 5.3.7
The class in question (src/subcommands/index.ts)
Solution:Jump to solution
subcommand buckets can be accessed via the following:
...
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
43 Replies
I don't think I really understand what you mean you're doing but for starters you do need
MyCustomCommand extends Command and MyCustomSubcommand extends Subcommand so no commands without subcommands should not extend Subcommand. The WeakMap buckets for subcomands and c ommands are separate buckets and if you do the former you should be able to remove each from their respective buckets.So I may have to make my base class extend Subcommand to be able to handle its cooldowns, right? I looked through the declarations, my cooldowns are declared on a subcommand, and not a upper lever command.
yes, you always have to extend one of Comand or Subcommand. Without they would not be registered and you would be missing many methods for actually handling them
Because I basically have a class that acts like a group, and then my actual subcommands that run are just based off that class. Like this:
That's what I'm doing here.
Guess I should've been more specific as to what I'm doing here, my bad.
your folder structure are already groups internally. Every piece has a property called location which has several properties to group your commands
So I should probably pass that in through a constructor or something, right?
Or am I reading this wrong?
s!ev this.command.location
Output: ⏱ 310.02μs
It's there by default
you can use that to group things i.e. in a help command
you dont need to do it yourself
Yeah, just saw that.
Sorry, just came back to TypeScript after a bit and I'm still kinda new to this framework.
nothing to apologize for
Hmm... trying to think about this while I try to get some help. Should I try passing through all the subcommand preconditions when the command runs?
huh?
Just found
this.subcommandPreconditions, but that doesn't seem to be right.I dont understand what you want to achieve
I might just have to rewrite my commands to just return a
boolean and then remove the cooldown based on that.I'm still confused. Cooldowns are removed automatically when they expire. Are you saying you want to remove them manually under certain conditions?
Yeah, that's basically what I want to do.
Kinda like:
And I did read the forums on doing that in actual classes that extend
Command or Subcommand, but I never found one for my specific use case.Let me try that. One moment.
Hmm... deprecated and invalid.
?
it shouldnt be

Typed all that out, white line over
SubcommandPreconditions, and it didn't see subcommandBuckets.
I forgor we scheduled that
it's just that the import changes and you dont need the
SubcommandPreconditions. part anymoreAll right. Let me look through this, one moment.
as for it not being there
uuhhh
that is a problem
it's typed as the class instead of an instance of the class that's weird
How long has that been deprecated for? Like... since 5.1?
And should I try going to the next major version right now?
I think so but it isnt saying that it will be removed say tomorrow. It's just a general reminder it may happen in the future.
the next major version might be a year, 2 years, or never. It happens when it's required for different reasons to release a semver major.
we never bump willy nilly
anyway im trying to figure this out because I swear it was possible but I cannot find it anymore either
Yeah, I just saw the next major version is listed on NPM, if this is it.

i can't find how to get the cooldowns anymore either
Under which conditions did you exactly want to be able to remove the cooldown from the given context anyway if I may ask?
Should I try going to the next major version then?
no that wont change anything
Ah, all right. Let's say for example my command requires a user document from the DB, and none was found (this was handled by a different precondition, but this is an example), then I'd like to tell the user the issue and then reset the cooldown so they don't get punished for no reason. Or if they decline something essential to the command or something like that.
If that makes sense.
Kinda got the tell the user part, just not the resetting part.
for regular non subcomand preconditions I believe this is the way to get access to the WeakMap buckets
(might not be 100% accurate, I havent ran it, just written it out checking TS errors)
All right. Let me see here...
I believe subcommands should be similar. From the top of my head I forgor where they are stored in stores
All right, all the cooldowns are in subcommands...
Wait, one moment...
This might be the biggest impasse I've been at ever, and it's nothing to do with this framework.
I might have to leave the code as-is and just not reset cooldowns until there's a solid solution to this.
Because the only other option is making every command really brittle and repeating myself.
If you think you can have a design to do it in a good way then feel free to make a PR
Solution
subcommand buckets can be accessed via the following:
and an example with types: https://tsplay.dev/N94o9w
TS Playground - An online editor for exploring TypeScript and JavaS...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Thanks :peeposaber: I knew it had to be somewhere
Ooh, yeah. That actually helped! I might be getting somewhere now!
It's solved! We're good!