@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
42 lines (40 loc) • 1.45 kB
JavaScript
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/GuildTextOnly.ts
var CorePrecondition = class extends AllFlowsPrecondition {
constructor(..._args) {
super(..._args);
this.allowedTypes = [
ChannelType.GuildText,
ChannelType.PublicThread,
ChannelType.PrivateThread
];
}
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.PreconditionGuildTextOnly,
message: "You can only run this command in server text channels."
});
}
};
container.stores.loadPiece({
name: "GuildTextOnly",
piece: CorePrecondition,
store: "preconditions"
});
//#endregion
export { CorePrecondition };
//# sourceMappingURL=GuildTextOnly.mjs.map