UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

38 lines (36 loc) 1.43 kB
import { Identifiers } from "../lib/errors/Identifiers.mjs"; import { AllFlowsPrecondition } from "../lib/structures/Precondition.mjs"; import { container } from "@sapphire/pieces"; import { ChannelType, ChatInputCommandInteraction, ContextMenuCommandInteraction, Message } from "discord.js"; //#region src/preconditions/GuildNewsOnly.ts var CorePrecondition = class extends AllFlowsPrecondition { constructor(..._args) { super(..._args); this.allowedTypes = [ChannelType.GuildAnnouncement, ChannelType.AnnouncementThread]; } messageRun(message) { return this.allowedTypes.includes(message.channel.type) ? this.ok() : this.makeSharedError(); } async chatInputRun(interaction) { const channel = await this.fetchChannelFromInteraction(interaction); return this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError(); } async contextMenuRun(interaction) { const channel = await this.fetchChannelFromInteraction(interaction); return this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError(); } makeSharedError() { return this.error({ identifier: Identifiers.PreconditionGuildNewsOnly, message: "You can only run this command in server announcement channels." }); } }; container.stores.loadPiece({ name: "GuildNewsOnly", piece: CorePrecondition, store: "preconditions" }); //#endregion export { CorePrecondition }; //# sourceMappingURL=GuildNewsOnly.mjs.map