UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 1.2 kB
{"version":3,"file":"channel.mjs","names":[],"sources":["../../../../src/lib/resolvers/channel.ts"],"sourcesContent":["import { ChannelMentionRegex, type ChannelTypes } from '@sapphire/discord.js-utilities';\nimport { container } from '@sapphire/pieces';\nimport { Result } from '@sapphire/result';\nimport type { CommandInteraction, Message, Snowflake } from 'discord.js';\nimport { Identifiers } from '../errors/Identifiers';\n\nexport function resolveChannel(\n\tparameter: string,\n\tmessageOrInteraction: Message | CommandInteraction\n): Result<ChannelTypes, Identifiers.ArgumentChannelError> {\n\tconst channelId = (ChannelMentionRegex.exec(parameter)?.[1] ?? parameter) as Snowflake;\n\tconst channel = (messageOrInteraction.guild ? messageOrInteraction.guild.channels : container.client.channels).cache.get(channelId);\n\n\tif (channel) {\n\t\treturn Result.ok(channel as ChannelTypes);\n\t}\n\n\treturn Result.err(Identifiers.ArgumentChannelError);\n}\n"],"mappings":";;;;;;AAMA,SAAgB,eACf,WACA,sBACyD;CACzD,MAAM,YAAa,oBAAoB,KAAK,UAAU,GAAG,MAAM;CAC/D,MAAM,WAAW,qBAAqB,QAAQ,qBAAqB,MAAM,WAAW,UAAU,OAAO,UAAU,MAAM,IAAI,UAAU;AAEnI,KAAI,QACH,QAAO,OAAO,GAAG,QAAwB;AAG1C,QAAO,OAAO,IAAI,YAAY,qBAAqB"}