import { container, Precondition } from "@sapphire/framework"; import config from "@stealth-developers/config"; import type { ChatInputCommandInteraction, ContextMenuCommandInteraction } from "discord.js"; export class GuildCheckPrecondition extends Precondition { public override chatInputRun(interaction: ChatInputCommandInteraction) { if (!interaction.guildId) return this.error({ message: "This command can only be used in a server." }); if (interaction.guildId === config.discord.server.id) return this.ok(); return this.error({ message: "This command can only be used in the configured server.", identifier: "CONFIGURED_GUILD_ONLY", }); } public override contextMenuRun(interaction: ContextMenuCommandInteraction) { if (interaction.guildId !== config.discord.server.id) return this.ok(); return this.error({ message: "This command can only be used in the configured server.", identifier: "CONFIGURED_GUILD_ONLY", }); } } declare module "@sapphire/framework" { interface Preconditions { GuildCheck: never; } } container.stores.loadPiece({ name: "GuildCheck", piece: GuildCheckPrecondition, store: "preconditions", });