all repos — stealth-developers @ 6a0d732c9b3a37dd1086739ca3bacf5c6e9f8431

apps/bot/src/preconditions/guild.ts (view raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
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.guild) 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.guild) 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",
});