Is there a way to hide command if the user doesn't have the precondition ?

No description
Solution:
That's correct. Server settings and setting it at register level are configuring it on the Discord API side which means a command can be hidden from users because at that point it's simply to sent to them from the API. Preconditions however are runtime checks and essentially just glorified if checks.
Jump to solution
11 Replies
simnJS
simnJSOP5mo ago
And this is the procondition
import { Precondition } from '@sapphire/framework';
import type { CommandInteraction, ContextMenuCommandInteraction, Message } from 'discord.js';
import botowners from '../config.json';

export class OwnerOnlyPrecondition extends Precondition {
public override async messageRun(message: Message) {
return this.checkOwner(message.author.id);
}

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

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

private async checkOwner(userId: string) {
return botowners.bot_owners.includes(userId)
? this.ok()
: this.error({ message: 'Only the bot owner can use this command!' });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnersOnly: never;
}
}


export default undefined;
import { Precondition } from '@sapphire/framework';
import type { CommandInteraction, ContextMenuCommandInteraction, Message } from 'discord.js';
import botowners from '../config.json';

export class OwnerOnlyPrecondition extends Precondition {
public override async messageRun(message: Message) {
return this.checkOwner(message.author.id);
}

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

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

private async checkOwner(userId: string) {
return botowners.bot_owners.includes(userId)
? this.ok()
: this.error({ message: 'Only the bot owner can use this command!' });
}
}

declare module '@sapphire/framework' {
interface Preconditions {
OwnersOnly: never;
}
}


export default undefined;
čamdžić
čamdžić5mo ago
nope only in server settings i think since it's slash command
Solution
Favna
Favna5mo ago
That's correct. Server settings and setting it at register level are configuring it on the Discord API side which means a command can be hidden from users because at that point it's simply to sent to them from the API. Preconditions however are runtime checks and essentially just glorified if checks.
simnJS
simnJSOP5mo ago
So there is no tips to hide owner only command
čamdžić
čamdžić5mo ago
you can register these commands only to your owner guild and they'll be only there
Favna
Favna5mo ago
What Camdzic said or make owner only commands message commands
simnJS
simnJSOP5mo ago
how ?
čamdžić
čamdžić5mo ago
Sapphire Framework
Registering Chat Input Commands | Sapphire
To register a Chat Input Command (also known as a Slash Command) with Discord, you need to acquire an application
čamdžić
čamdžić5mo ago
i think this is what you're looking for
simnJS
simnJSOP5mo ago
ty
Want results from more Discord servers?
Add your server