UNPKG

@sapphire/framework

Version:

Discord bot framework built for advanced and amazing bots.

1 lines 2.47 kB
{"version":3,"file":"getNeededParameters.cjs","names":["container"],"sources":["../../../../../src/lib/utils/application-commands/getNeededParameters.ts"],"sourcesContent":["import { container } from '@sapphire/pieces';\nimport type { ApplicationCommand, ApplicationCommandManager, Collection } from 'discord.js';\n\nexport async function getNeededRegistryParameters(guildIds: Set<string> = new Set()) {\n\tconst { client } = container;\n\n\tconst applicationCommands = client.application!.commands;\n\tconst globalCommands = await applicationCommands.fetch({ withLocalizations: true });\n\tconst guildCommands = await fetchGuildCommands(applicationCommands, guildIds);\n\n\treturn {\n\t\tapplicationCommands,\n\t\tglobalCommands,\n\t\tguildCommands\n\t};\n}\n\nasync function fetchGuildCommands(commands: ApplicationCommandManager, guildIds: Set<string>) {\n\tconst map = new Map<string, Collection<string, ApplicationCommand>>();\n\n\tfor (const guildId of guildIds) {\n\t\ttry {\n\t\t\tconst guildCommands = await commands.fetch({ guildId, withLocalizations: true });\n\t\t\tmap.set(guildId, guildCommands);\n\t\t} catch (err) {\n\t\t\tconst { preventFailedToFetchLogForGuilds } = container.client.options;\n\n\t\t\tif (preventFailedToFetchLogForGuilds === true) continue;\n\n\t\t\tif (Array.isArray(preventFailedToFetchLogForGuilds) && !preventFailedToFetchLogForGuilds?.includes(guildId)) {\n\t\t\t\tconst guild = container.client.guilds.resolve(guildId) ?? { name: 'Guild not in cache' };\n\t\t\t\tcontainer.logger.warn(\n\t\t\t\t\t`ApplicationCommandRegistries: Failed to fetch guild commands for guild \"${guild.name}\" (${guildId}).`,\n\t\t\t\t\t'Make sure to authorize your application with the \"applications.commands\" scope in that guild.'\n\t\t\t\t);\n\t\t\t}\n\t\t}\n\t}\n\n\treturn map;\n}\n"],"mappings":";;;;AAGA,eAAsB,4BAA4B,2BAAwB,IAAI,KAAK,EAAE;CACpF,MAAM,EAAE,WAAWA;CAEnB,MAAM,sBAAsB,OAAO,YAAa;AAIhD,QAAO;EACN;EACA,gBALsB,MAAM,oBAAoB,MAAM,EAAE,mBAAmB,MAAM,CAAC;EAMlF,eALqB,MAAM,mBAAmB,qBAAqB,SAAS;EAM5E;;AAGF,eAAe,mBAAmB,UAAqC,UAAuB;CAC7F,MAAM,sBAAM,IAAI,KAAqD;AAErE,MAAK,MAAM,WAAW,SACrB,KAAI;EACH,MAAM,gBAAgB,MAAM,SAAS,MAAM;GAAE;GAAS,mBAAmB;GAAM,CAAC;AAChF,MAAI,IAAI,SAAS,cAAc;UACvB,KAAK;EACb,MAAM,EAAE,qCAAqCA,4BAAU,OAAO;AAE9D,MAAI,qCAAqC,KAAM;AAE/C,MAAI,MAAM,QAAQ,iCAAiC,IAAI,CAAC,kCAAkC,SAAS,QAAQ,EAAE;GAC5G,MAAM,QAAQA,4BAAU,OAAO,OAAO,QAAQ,QAAQ,IAAI,EAAE,MAAM,sBAAsB;AACxF,+BAAU,OAAO,KAChB,2EAA2E,MAAM,KAAK,KAAK,QAAQ,KACnG,kGACA;;;AAKJ,QAAO"}