OwnerOnly precondition not working

Hello there. I just yoinked the OwnerOnly precondition from the guide and the Github repo but I just can't make it work. I don't get an error, I also yoinked the precondition failure messages, I don't get any info about why its not working. I only get "The application did not respond". Without the precondition my command works. OwnerOnly.ts
import { Precondition } from '@sapphire/framework';

import type {
CommandInteraction,
ContextMenuCommandInteraction,
Message,
Snowflake,
} from 'discord.js';

export class UserPrecondition extends Precondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return userId === '447000659871662081'
? this.ok()
: this.error({ message: this.#message });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}
import { Precondition } from '@sapphire/framework';

import type {
CommandInteraction,
ContextMenuCommandInteraction,
Message,
Snowflake,
} from 'discord.js';

export class UserPrecondition extends Precondition {
#message = 'This command can only be used by the owner.';

public override chatInputRun(interaction: CommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override contextMenuRun(interaction: ContextMenuCommandInteraction) {
return this.doOwnerCheck(interaction.user.id);
}

public override messageRun(message: Message) {
return this.doOwnerCheck(message.author.id);
}

private doOwnerCheck(userId: Snowflake) {
return userId === '447000659871662081'
? this.ok()
: this.error({ message: this.#message });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnerOnly: never;
}
}
Solution:
fixed it
Jump to solution
8 Replies
bonk
bonkOPโ€ข14mo ago
Da command
import { Command, type ApplicationCommandRegistry } from '@sapphire/framework';
import { type ChatInputCommandInteraction } from 'discord.js';
import { ApplyOptions } from '@sapphire/decorators';

@ApplyOptions<Command.Options>({
name: 'restart',
description: 'Restarts the bot',
preconditions: ["OwnerOnly"]
})
export class RestartCommand extends Command {
public override registerApplicationCommands(
registry: ApplicationCommandRegistry
) {
registry.registerChatInputCommand((command) => {
command.setName(this.name).setDescription(this.description);
});
}

public async chatInputRun(interaction: ChatInputCommandInteraction) {
await interaction.reply({
content: 'Restarting...',
ephemeral: true,
});

await this.container.client.destroy();
await this.container.client.login(process.env.BOT_TOKEN);
}
}
import { Command, type ApplicationCommandRegistry } from '@sapphire/framework';
import { type ChatInputCommandInteraction } from 'discord.js';
import { ApplyOptions } from '@sapphire/decorators';

@ApplyOptions<Command.Options>({
name: 'restart',
description: 'Restarts the bot',
preconditions: ["OwnerOnly"]
})
export class RestartCommand extends Command {
public override registerApplicationCommands(
registry: ApplicationCommandRegistry
) {
registry.registerChatInputCommand((command) => {
command.setName(this.name).setDescription(this.description);
});
}

public async chatInputRun(interaction: ChatInputCommandInteraction) {
await interaction.reply({
content: 'Restarting...',
ephemeral: true,
});

await this.container.client.destroy();
await this.container.client.login(process.env.BOT_TOKEN);
}
}
Solution
bonk
bonkโ€ข14mo ago
fixed it
Favna
Favnaโ€ข14mo ago
Please elaborate on what you had to change for future readers
nonsensetwice
nonsensetwiceโ€ข14mo ago
What did you do to fix it? I'm running into an issue where the check will get as far as the ternary operator and then it hangs with no error info ๐Ÿ˜ซ
bonk
bonkOPโ€ข14mo ago
After i made the failure messages work it said the "OwnerOnly" is unavailable, so I tried renaming the file, etc. and then it just worked for some reason. Also i checked some repos linked here under tag how they made their BotOwner precondition. https://github.com/SpecteraLabs/Spectera/blob/main/src/preconditions/BotOwner.ts https://github.com/SpecteraLabs/Spectera/blob/main/src/listeners/commands/chatInputCommandDenied.ts This made it work for me (thank you Spectera if you read this somehow). It could also work with the precondition in the guide by renaming it to smth like "BotOwner", I didn't try that
GitHub
Spectera/src/preconditions/BotOwner.ts at main ยท SpecteraLabs/Spect...
A multipurpose discord bot which is still being made :zap: - SpecteraLabs/Spectera
GitHub
Spectera/src/listeners/commands/chatInputCommandDenied.ts at main ยท...
A multipurpose discord bot which is still being made :zap: - SpecteraLabs/Spectera
bonk
bonkOPโ€ข14mo ago
@nonsensetwice
nonsensetwice
nonsensetwiceโ€ข14mo ago
๐Ÿค” I'll have to examine this. Thanks for the details. I'll take another crack at it later this evening ๐Ÿ™
bonk
bonkOPโ€ข14mo ago
You're welcome! You could also use the CLI, generate a new project and just put your stuff in there, this works too. I don't really exactly know what the issue is but yeah. ๐Ÿ™‚
Want results from more Discord servers?
Add your server