Files
discordeno/helpers/interactions/commands/getApplicationCommand.ts
ITOH 34a358f8bf feat(helpers,types)!: slash command localization (#2129)
* feat(helpers,types): slash command localization
Discord has documented the slash command localization feature now.
This adds the full functionality for those to Discordeno.

Additionally a `Locales` has also been added to allow for better typing.

Reference: https://github.com/discord/discord-api-docs/pull/4653

* suggestion

* better locales type

* f

* fix serializing

* stupid direct pushes

* b
2022-03-27 11:02:27 -04:00

32 lines
1.3 KiB
TypeScript

import type { Bot } from "../../../bot.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
/** Fetches the global command for the given Id. If a guildId is provided, the guild command will be fetched. */
export async function getApplicationCommand(bot: Bot, commandId: bigint, options?: GetApplicationCommand) {
let url = `${
options?.guildId
? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, options.guildId, commandId)
: bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId)
}?`;
if (options?.withLocalizations !== undefined) {
url += `with_localizations=${options.withLocalizations}`;
}
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"get",
url,
);
return bot.transformers.applicationCommand(bot, result);
}
/** https://discord.com/developers/docs/interactions/application-commands#endpoints-query-string-params */
export interface GetApplicationCommand {
/** Guild ID of the guild in which the command is available if it is a guild-specific command */
guildId?: bigint;
/** Whether to include full localization object (`name_localizations` and `description_localizations`) in the returned objects, instead of the `name_localized` and `description_localized` fields. Default false */
withLocalizations?: boolean;
}