#Cooldown filter precondition
1 messages · Page 1 of 1 (latest)
Extend the class and override the methods
Would it be something like this?
import { Precondition } from "@sapphire/framework";
import {
Subcommand,
SubcommandPreconditions,
} from "@sapphire/plugin-subcommands";
import type { ChatInputCommandInteraction } from "discord.js";
const allowedRole = "920834418459967548";
export class UserPrecondition extends SubcommandPreconditions.PluginSubcommandCooldown {
public constructor(
context: Precondition.LoaderContext,
options: Precondition.Options
) {
super(context, {
...options,
name: "CustomCooldown",
});
}
public override async chatInputRun(
interaction: ChatInputCommandInteraction,
subcommand: Subcommand,
context: SubcommandPreconditions.PluginSubcommandCooldownContext
) {
if (
interaction.inCachedGuild() &&
interaction.guild.roles.cache.get(allowedRole)
) {
return this.ok();
}
return super.chatInputRun(interaction, subcommand, context);
}
}
declare module "@sapphire/framework" {
interface Preconditions {
CustomCooldown: never;
}
}
That restricts outright rather than being a cooldown but other than that, yes
If you're going that route I would recommend just extending Precondition instead of SubcommandPreconditions.PluginSubcommandCooldown
Yeah i realised afterwards that it didn't work as intended. and the precondition didn't run 😦
I wanted to extend the cooldown precondition method because I'm not sure how to code the cooldown myself. So i thought to just add to the super method
The code is open source on github 🙂 you can just copy pasta code