@sapphire/framework
Version:
Discord bot framework built for advanced and amazing bots.
22 lines (20 loc) • 957 B
JavaScript
import { Identifiers } from "../errors/Identifiers.mjs";
import { Result } from "@sapphire/result";
import { ChannelMentionRegex, SnowflakeRegex } from "@sapphire/discord-utilities";
//#region src/lib/resolvers/guildChannel.ts
function resolveGuildChannel(parameter, guild) {
const channel = resolveById(parameter, guild) ?? resolveByQuery(parameter, guild);
if (channel) return Result.ok(channel);
return Result.err(Identifiers.ArgumentGuildChannelError);
}
function resolveById(argument, guild) {
const channelId = ChannelMentionRegex.exec(argument) ?? SnowflakeRegex.exec(argument);
return channelId ? guild.channels.cache.get(channelId[1]) ?? null : null;
}
function resolveByQuery(argument, guild) {
const lowerCaseArgument = argument.toLowerCase();
return guild.channels.cache.find((channel) => channel.name.toLowerCase() === lowerCaseArgument) ?? null;
}
//#endregion
export { resolveGuildChannel };
//# sourceMappingURL=guildChannel.mjs.map