UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 2.34 kB
{"version":3,"file":"GuildTextOnly.mjs","names":[],"sources":["../../../src/preconditions/GuildTextOnly.ts"],"sourcesContent":["import { container } from '@sapphire/pieces';\nimport { ChannelType, ChatInputCommandInteraction, ContextMenuCommandInteraction, Message, type TextBasedChannelTypes } from 'discord.js';\nimport { Identifiers } from '../lib/errors/Identifiers';\nimport { AllFlowsPrecondition } from '../lib/structures/Precondition';\n\nexport class CorePrecondition extends AllFlowsPrecondition {\n\tprivate readonly allowedTypes: TextBasedChannelTypes[] = [ChannelType.GuildText, ChannelType.PublicThread, ChannelType.PrivateThread];\n\n\tpublic messageRun(message: Message): AllFlowsPrecondition.Result {\n\t\treturn this.allowedTypes.includes(message.channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tpublic async chatInputRun(interaction: ChatInputCommandInteraction): AllFlowsPrecondition.AsyncResult {\n\t\tconst channel = await this.fetchChannelFromInteraction(interaction);\n\t\treturn this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tpublic async contextMenuRun(interaction: ContextMenuCommandInteraction): AllFlowsPrecondition.AsyncResult {\n\t\tconst channel = await this.fetchChannelFromInteraction(interaction);\n\t\treturn this.allowedTypes.includes(channel.type) ? this.ok() : this.makeSharedError();\n\t}\n\n\tprivate makeSharedError(): AllFlowsPrecondition.Result {\n\t\treturn this.error({\n\t\t\tidentifier: Identifiers.PreconditionGuildTextOnly,\n\t\t\tmessage: 'You can only run this command in server text channels.'\n\t\t});\n\t}\n}\n\nvoid container.stores.loadPiece({\n\tname: 'GuildTextOnly',\n\tpiece: CorePrecondition,\n\tstore: 'preconditions'\n});\n"],"mappings":";;;;;;AAKA,IAAa,mBAAb,cAAsC,qBAAqB;;;OACzC,eAAwC;GAAC,YAAY;GAAW,YAAY;GAAc,YAAY;GAAc;;CAErI,AAAO,WAAW,SAA+C;AAChE,SAAO,KAAK,aAAa,SAAS,QAAQ,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAG7F,MAAa,aAAa,aAA4E;EACrG,MAAM,UAAU,MAAM,KAAK,4BAA4B,YAAY;AACnE,SAAO,KAAK,aAAa,SAAS,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAGrF,MAAa,eAAe,aAA8E;EACzG,MAAM,UAAU,MAAM,KAAK,4BAA4B,YAAY;AACnE,SAAO,KAAK,aAAa,SAAS,QAAQ,KAAK,GAAG,KAAK,IAAI,GAAG,KAAK,iBAAiB;;CAGrF,AAAQ,kBAA+C;AACtD,SAAO,KAAK,MAAM;GACjB,YAAY,YAAY;GACxB,SAAS;GACT,CAAC;;;AAIC,UAAU,OAAO,UAAU;CAC/B,MAAM;CACN,OAAO;CACP,OAAO;CACP,CAAC"}