preconditions don't run

I have a precondition (src/preconditions/Setup.ts) being used in a subcommand command (src/commands/setup.ts) and neither the command nor precondition run. I've added debug console.log's to both, and neither output whenever I use the command. I can provide a project .zip in DMs upon request.
19 Replies
b1nzee
b1nzee2y ago
No need to provide a .zip Just send your precondition code Also make sure your startup file is defined in your package.json under main
jack.ink
jack.inkOP2y ago
import { Precondition } from "@sapphire/framework";
import type {
ChatInputCommandInteraction,
ContextMenuCommandInteraction,
} from "discord.js";

export class UserPrecondition extends Precondition {
public override chatInputRun(interaction: ChatInputCommandInteraction) {
return this.ok();
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.ok();
}
}

declare module "@sapphire/framework" {
interface Preconditions {
Setup: never;
}
}
import { Precondition } from "@sapphire/framework";
import type {
ChatInputCommandInteraction,
ContextMenuCommandInteraction,
} from "discord.js";

export class UserPrecondition extends Precondition {
public override chatInputRun(interaction: ChatInputCommandInteraction) {
return this.ok();
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.ok();
}
}

declare module "@sapphire/framework" {
interface Preconditions {
Setup: never;
}
}
and my startup file is properly defined
b1nzee
b1nzee2y ago
Hmmm that should work But you also mentioned the subcommand doesn't run, so let's see that code too
jack.ink
jack.inkOP2y ago
export class Config extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: "config",
description: "Config all the settings for the group.",
preconditions: ["Setup"],
subcommands: [
{
name: "verified",
chatInputRun: "setVerifiedRole",
},
{
name: "ranks",
type: "group",

entries: [
{
name: "load",
chatInputRun: "loadRanks",
},
],
},
],
});
}

public registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand(
builder => {
builder
.setName(this.name)
.setDescription(this.description)
.addSubcommand(command =>
command
.setName("verified")
.setDescription("Change the verified role")
.addRoleOption(option =>
option
.setName("role")
.setDescription(
"The role to give verified users, or none to not give them a role",
)
.setRequired(false),
),
)
.addSubcommandGroup(group =>
group
.setName("ranks")
.setDescription("Change configuration related to ranks")
.addSubcommand(command =>
command
.setName("load")
.setDescription("Load all ranks from the roblox group"),
),
);
},
{
idHints: ["1137656879930146836"],
},
);
}

...
}
export class Config extends Subcommand {
public constructor(context: Subcommand.Context, options: Subcommand.Options) {
super(context, {
...options,
name: "config",
description: "Config all the settings for the group.",
preconditions: ["Setup"],
subcommands: [
{
name: "verified",
chatInputRun: "setVerifiedRole",
},
{
name: "ranks",
type: "group",

entries: [
{
name: "load",
chatInputRun: "loadRanks",
},
],
},
],
});
}

public registerApplicationCommands(registry: Subcommand.Registry) {
registry.registerChatInputCommand(
builder => {
builder
.setName(this.name)
.setDescription(this.description)
.addSubcommand(command =>
command
.setName("verified")
.setDescription("Change the verified role")
.addRoleOption(option =>
option
.setName("role")
.setDescription(
"The role to give verified users, or none to not give them a role",
)
.setRequired(false),
),
)
.addSubcommandGroup(group =>
group
.setName("ranks")
.setDescription("Change configuration related to ranks")
.addSubcommand(command =>
command
.setName("load")
.setDescription("Load all ranks from the roblox group"),
),
);
},
{
idHints: ["1137656879930146836"],
},
);
}

...
}
its a very large command, so I didn't put in the actual code but one important thing to note is that when I tested it without any preconditions it worked as expected when I place a debug console.log anywhere in the precondition or the command, they just don't output when there is a precondition
b1nzee
b1nzee2y ago
Hmmm that's weird @Favna ?
jack.ink
jack.inkOP2y ago
its very weird, if you need a zip for some obscure detail I can provide
b1nzee
b1nzee2y ago
No zip needed, I've seen everything that's relevant
jack.ink
jack.inkOP2y ago
alright
Favna
Favna2y ago
Send Package.json pls @jack
b1nzee
b1nzee2y ago
@jack.ink
jack.ink
jack.inkOP2y ago
{
"type": "module",
"main": "out/index.js",
"dependencies": {
"@sapphire/discord.js-utilities": "^7.0.1",
"@sapphire/framework": "^4.5.1",
"@sapphire/plugin-subcommands": "^4.0.2",
"discord.js": "^14.12.1",
"drizzle-orm": "^0.27.2",
"express": "^4.18.2",
"mysql2": "^3.6.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"drizzle-kit": "^0.19.12",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"prettier": "^3.0.0",
"typescript": "^5.1.6"
},
"scripts": {
"start": "tsc && node out/index"
}
}
{
"type": "module",
"main": "out/index.js",
"dependencies": {
"@sapphire/discord.js-utilities": "^7.0.1",
"@sapphire/framework": "^4.5.1",
"@sapphire/plugin-subcommands": "^4.0.2",
"discord.js": "^14.12.1",
"drizzle-orm": "^0.27.2",
"express": "^4.18.2",
"mysql2": "^3.6.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^6.2.1",
"@typescript-eslint/parser": "^6.2.1",
"drizzle-kit": "^0.19.12",
"eslint": "^8.46.0",
"eslint-config-prettier": "^8.9.0",
"prettier": "^3.0.0",
"typescript": "^5.1.6"
},
"scripts": {
"start": "tsc && node out/index"
}
}
Favna
Favna2y ago
Uhm that looks .. fine.. I would appreciate the zip. That said, I'm at an airport right now so it'll be a bunch of hours before I can check.
jack.ink
jack.inkOP2y ago
I'll get that sent to you, I completely understand the delays @Favna could any of my tsconfig settings be important?
Favna
Favna2y ago
I suppose yes. You could send that.
jack.ink
jack.inkOP2y ago
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Node",
"strict": true,
"skipLibCheck": true,
"outDir": "out",
"rootDir": "src",
},
"exclude": [
"drizzle.config.ts"
]
}
{
"compilerOptions": {
"target": "ES2022",
"module": "ES2022",
"esModuleInterop": true,
"forceConsistentCasingInFileNames": true,
"moduleResolution": "Node",
"strict": true,
"skipLibCheck": true,
"outDir": "out",
"rootDir": "src",
},
"exclude": [
"drizzle.config.ts"
]
}
b1nzee
b1nzee2y ago
Have a safe flight
jack.ink
jack.inkOP2y ago
just checking if you've found anything
Favna
Favna2y ago
Haven't checked yet
jack.ink
jack.inkOP2y ago
alright, no issue for now I'm just running preconditions as if statements

Did you find this page helpful?