Files
discordeno/helpers/interactions/commands/upsertApplicationCommand.ts
ITOH b00504ce07 perf(plugins/helpers,rest,site,template)!: uppercase rest methods (#2252)
* perf(plugins/helpers,rest,site,template)!: uppercase rest methods
There is no need for us to pass the methods in lower case and then use the `toUpperCase()` method everywhere. Therefore this PR changes every lowercase method to be uppercase (eg. `"get"` => `"GET"`).

* template is old version
2022-05-25 20:45:51 +02:00

41 lines
1.3 KiB
TypeScript

import type { Bot } from "../../../bot.ts";
import {
CreateApplicationCommand,
CreateContextApplicationCommand,
isContextApplicationCommand,
makeOptionsForCommand,
} from "./createApplicationCommand.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
import { AtLeastOne } from "../../../types/shared.ts";
/**
* Edit an existing application command. If this command did not exist, it will create it.
*/
export async function upsertApplicationCommand(
bot: Bot,
commandId: bigint,
options: AtLeastOne<CreateApplicationCommand> | AtLeastOne<CreateContextApplicationCommand>,
guildId?: bigint,
) {
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"PATCH",
guildId
? bot.constants.routes.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId)
: bot.constants.routes.COMMANDS_ID(bot.applicationId, commandId),
isContextApplicationCommand(options)
? {
name: options.name,
type: options.type,
}
: {
name: options.name,
description: options.description,
type: options.type,
options: options.options ? makeOptionsForCommand(options.options) : undefined,
},
);
return bot.transformers.applicationCommand(bot, result);
}