Files
discordeno/transformers/applicationCommand.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

25 lines
1.0 KiB
TypeScript

import { Bot } from "../bot.ts";
import { DiscordApplicationCommand } from "../types/discord.ts";
import { Optionalize } from "../types/shared.ts";
export function transformApplicationCommand(bot: Bot, payload: DiscordApplicationCommand) {
const applicationCommand = {
id: bot.transformers.snowflake(payload.id),
applicationId: bot.transformers.snowflake(payload.application_id),
guildId: payload.guild_id ? bot.transformers.snowflake(payload.guild_id) : undefined,
name: payload.name,
nameLocalizations: payload.name_localizations,
description: payload.description,
descriptionLocalizations: payload.description_localizations,
defaultPermission: payload.default_permission ?? false,
type: payload.type,
version: payload.version,
options: payload.options?.map((option) => bot.transformers.applicationCommandOption(bot, option)),
};
return applicationCommand as Optionalize<typeof applicationCommand>;
}
export interface ApplicationCommand extends ReturnType<typeof transformApplicationCommand> {}