How to manual disable precondition?

Hi, i made precondition that automatically enabled
public constructor(context: AllFlowsPrecondition.LoaderContext) {
super(context, {
name: "RulesOnly",
position: 15, //before cooldown
});
}


declare module "@sapphire/framework" {
interface Preconditions {
RulesOnly: never;
}
}
public constructor(context: AllFlowsPrecondition.LoaderContext) {
super(context, {
name: "RulesOnly",
position: 15, //before cooldown
});
}


declare module "@sapphire/framework" {
interface Preconditions {
RulesOnly: never;
}
}
but i want to disable it for some commands, i dont know how can i do it, can anyone help me?
Solution:
i'd rather creating new instance ```ts declare module "@sapphire/framework" { interface CommandOptions {...
Jump to solution
8 Replies
čamdžić
čamdžić3mo ago
No description
čamdžić
čamdžić3mo ago
Maybe in run method of precondition you can have array of command names And if that command is executed you can just say return this.ok()
Solution
Vrdons
Vrdons3mo ago
i'd rather creating new instance
declare module "@sapphire/framework" {
interface CommandOptions {
rulesDisabled?: boolean;
}
}
declare module "@sapphire/framework" {
interface CommandOptions {
rulesDisabled?: boolean;
}
}
public override async chatInputRun(
interaction: CommandInteraction,
command: ChatInputCommand
) {
if (command.options.rulesDisabled) return this.ok();
public override async chatInputRun(
interaction: CommandInteraction,
command: ChatInputCommand
) {
if (command.options.rulesDisabled) return this.ok();
@ApplyOptions<Command.Options>({
name: "-status",
cooldownDelay: 10000,
fullCategory: ["General"],
cooldownLimit: 1,
rulesDisabled:true
})
@ApplyOptions<Command.Options>({
name: "-status",
cooldownDelay: 10000,
fullCategory: ["General"],
cooldownLimit: 1,
rulesDisabled:true
})
čamdžić
čamdžić3mo ago
Uh I don’t see where you use CommandOptions here Can u show where did u put CommandOptions interface
Vrdons
VrdonsOP3mo ago
my bad sorry
čamdžić
čamdžić3mo ago
That’s okay I do it this way One sec
import { Command } from '@sapphire/framework';

export abstract class GarfieldCommand extends Command {
override permissionLevel: number;
override usage: string;
override hidden: boolean;

constructor(
context: Command.LoaderContext,
options: GarfieldCommand.Options
) {
super(context, options);

const { permissionLevel = 0, usage = '', hidden = false } = options;

this.permissionLevel = permissionLevel;
this.usage = usage;
this.hidden = hidden;
}
}

export namespace GarfieldCommand {
export interface Options extends Command.Options {
permissionLevel?: number;
usage?: string;
hidden?: boolean;
}
}
import { Command } from '@sapphire/framework';

export abstract class GarfieldCommand extends Command {
override permissionLevel: number;
override usage: string;
override hidden: boolean;

constructor(
context: Command.LoaderContext,
options: GarfieldCommand.Options
) {
super(context, options);

const { permissionLevel = 0, usage = '', hidden = false } = options;

this.permissionLevel = permissionLevel;
this.usage = usage;
this.hidden = hidden;
}
}

export namespace GarfieldCommand {
export interface Options extends Command.Options {
permissionLevel?: number;
usage?: string;
hidden?: boolean;
}
}
Then I just augment it And use in precondition like you Basically I extend GarfieldCommand instead of sapphire’s Command class
Vrdons
VrdonsOP3mo ago
yeah that would work did it work?
čamdžić
čamdžić3mo ago
Yeah It’s type safe and works really good

Did you find this page helpful?