I honestly haven't done this in a while (not since pre-application commands) and am new to using Sapphire. Looking to restrict a command to only be visible/usable by the server's owner and any roles they define. How is this best handled with Sapphire and application commands? The bot in question has a database to store roles if that's needed.
Using TypeScript, here's a basic command I wrote that I want to restrict as described:
// commands/example.tsimport { ApplyOptions } from '@sapphire/decorators';import { Command } from '@sapphire/framework';@ApplyOptions<Command.Options>({ description: 'An example command, that should only be accessed by server owner and users with roles defined'})export class UserCommand extends Command { public override registerApplicationCommands(registry: Command.Registry) { registry.registerChatInputCommand((builder) => builder .setName(this.name) .setDescription(this.description) ); } public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) { return interaction.reply(`Command example!`); }}
// commands/example.tsimport { ApplyOptions } from '@sapphire/decorators';import { Command } from '@sapphire/framework';@ApplyOptions<Command.Options>({ description: 'An example command, that should only be accessed by server owner and users with roles defined'})export class UserCommand extends Command { public override registerApplicationCommands(registry: Command.Registry) { registry.registerChatInputCommand((builder) => builder .setName(this.name) .setDescription(this.description) ); } public override async chatInputRun(interaction: Command.ChatInputCommandInteraction) { return interaction.reply(`Command example!`); }}
Already looked over docs and previous questions, though maybe I've missed something, call me out if I have haha