Skip to content

Commit 44bf46e

Browse files
kyranetfavna
andauthored
fix: register cooldown correctly (#304)
Co-authored-by: Jeroen Claassens <[email protected]>
1 parent 873c2d5 commit 44bf46e

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

src/lib/structures/Command.ts

+11-8
Original file line numberDiff line numberDiff line change
@@ -231,18 +231,21 @@ export abstract class Command<T = Args, O extends CommandOptions = CommandOption
231231
* @param options The command options given from the constructor.
232232
*/
233233
protected parseConstructorPreConditionsCooldown(options: CommandOptions) {
234-
const { cooldownLimit, cooldownDelay, cooldownScope, cooldownFilteredUsers } = options;
235234
const { defaultCooldown } = this.container.client.options;
236235

237-
if ((defaultCooldown && !defaultCooldown.filteredCommands?.includes(this.name)) || (cooldownLimit && cooldownDelay)) {
236+
// We will check for whether the command is filtered from the defaults, but we will allow overridden values to
237+
// be set. If an overridden value is passed, it will have priority. Otherwise it will default to 0 if filtered
238+
// (causing the precondition to not be registered) or the default value with a fallback to a single-use cooldown.
239+
const filtered = defaultCooldown?.filteredCommands?.includes(this.name) ?? false;
240+
const limit = options.cooldownLimit ?? (filtered ? 0 : defaultCooldown!.limit ?? 1);
241+
const delay = options.cooldownDelay ?? (filtered ? 0 : defaultCooldown!.delay ?? 0);
242+
243+
if (limit && delay) {
244+
const scope = options.cooldownScope ?? defaultCooldown?.scope ?? BucketScope.User;
245+
const filteredUsers = options.cooldownFilteredUsers ?? defaultCooldown?.filteredUsers;
238246
this.preconditions.append({
239247
name: CommandPreConditions.Cooldown,
240-
context: {
241-
scope: cooldownScope ?? defaultCooldown?.scope ?? BucketScope.User,
242-
limit: cooldownLimit ?? defaultCooldown?.limit ?? 1,
243-
delay: cooldownDelay ?? defaultCooldown?.delay ?? 0,
244-
filteredUsers: cooldownFilteredUsers ?? defaultCooldown?.filteredUsers
245-
}
248+
context: { scope, limit, delay, filteredUsers }
246249
});
247250
}
248251
}

0 commit comments

Comments
 (0)