Files
discordeno/helpers/interactions/commands/upsertApplicationCommand.ts
Skillz4Killz a0a1554756 refactor: typings using ReturnType (#2105)
* fix: check new types idea

* fix: type errors

* fix: new style

* fix: more cleanup

* fix: more cleanup

* fix: cleanup audit logs

* fix: cleanup stickers

* fix: cleanup integrations

* fix: more cleanup

* fix: organize into 1 place

* fix: few errors

* fix: some broken import fixes

* fix: quite a lot of fixes across the board

* fix: more fixes for broken imports

* fix: more fixes for broken imports

* fix: handler imports

* fix: all remaining import errors

* fix: more errors needing fixes

* fix: clearing up transformers

* fix: few moer types

* fix: more cleanup of extra types

* fix: fmt

* fix: cleanup discordeno file

* Nuke Base Types (#2102)

* fix: cleanup snake stuff

* convert camelCase to snake_case (#2103)

* fix: add camelize

* fix: finalize remaining errors

* fix: imports in test

Co-authored-by: LTS20050703 <87189679+lts20050703@users.noreply.github.com>
2022-03-14 22:11:22 -04:00

46 lines
1.7 KiB
TypeScript

import type { Bot } from "../../../bot.ts";
import { makeOptionsForCommand } from "./createApplicationCommand.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
import { ApplicationCommandOption } from "../../../transformers/applicationCommandOption.ts";
import { ApplicationCommandTypes } 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: EditGlobalApplicationCommand,
guildId?: bigint,
) {
const result = await bot.rest.runMethod<DiscordApplicationCommand>(
bot.rest,
"patch",
guildId
? bot.constants.endpoints.COMMANDS_GUILD_ID(bot.applicationId, guildId, commandId)
: bot.constants.endpoints.COMMANDS_ID(bot.applicationId, commandId),
{
name: options.name,
description: options.description,
type: options.type,
options: options.options ? makeOptionsForCommand(options.options) : undefined,
},
);
return bot.transformers.applicationCommand(bot, result);
}
/** https://discord.com/developers/docs/interactions/slash-commands#edit-global-application-command-json-params */
export interface EditGlobalApplicationCommand {
/** 1-32 character name matching lowercase `^[\w-]{1,32}$` */
name?: string;
/** 1-100 character description */
description?: string;
/** The type of the command */
type?: ApplicationCommandTypes;
/** The parameters for the command */
options?: ApplicationCommandOption[] | null;
/** Whether the command is enabled by default when the app is added to a guild. Default: true */
defaultPermission?: boolean;
}