UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 1.27 kB
{"version":3,"file":"channel.cjs","names":["ChannelMentionRegex","container","Result","Identifiers"],"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,YAAaA,oDAAoB,KAAK,UAAU,GAAG,MAAM;CAC/D,MAAM,WAAW,qBAAqB,QAAQ,qBAAqB,MAAM,WAAWC,4BAAU,OAAO,UAAU,MAAM,IAAI,UAAU;AAEnI,KAAI,QACH,QAAOC,yBAAO,GAAG,QAAwB;AAG1C,QAAOA,yBAAO,IAAIC,2CAAY,qBAAqB"}