fix: typeguard for context cmds

This commit is contained in:
Skillz4Killz
2022-03-21 08:05:41 +00:00
committed by GitHub
parent 45b075c5b5
commit 67d8064be3
3 changed files with 62 additions and 37 deletions
@@ -1,8 +1,12 @@
import type { Bot } from "../../../bot.ts";
import { Collection } from "../../../util/collection.ts";
import { makeOptionsForCommand } from "./createApplicationCommand.ts";
import {
CreateApplicationCommand,
CreateContextApplicationCommand,
isContextApplicationCommand,
makeOptionsForCommand,
} from "./createApplicationCommand.ts";
import { DiscordApplicationCommand } from "../../../types/discord.ts";
import { EditGlobalApplicationCommand } from "./upsertApplicationCommand.ts";
import { MakeRequired } from "../../../types/shared.ts";
/**
@@ -12,7 +16,7 @@ import { MakeRequired } from "../../../types/shared.ts";
*/
export async function upsertApplicationCommands(
bot: Bot,
options: MakeRequired<EditGlobalApplicationCommand, "name">[],
options: (CreateApplicationCommand | CreateContextApplicationCommand)[],
guildId?: bigint,
) {
const result = await bot.rest.runMethod<DiscordApplicationCommand[]>(
@@ -21,13 +25,19 @@ export async function upsertApplicationCommands(
guildId
? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId)
: bot.constants.endpoints.COMMANDS(bot.applicationId),
options.map((option) => ({
name: option.name,
description: option.description,
type: option.type,
options: option.options ? makeOptionsForCommand(option.options) : undefined,
default_permission: option.defaultPermission,
})),
options.map((option) => (isContextApplicationCommand(option)
? {
name: option.name,
type: option.type,
}
: {
name: option.name,
description: option.description,
type: option.type,
options: option.options ? makeOptionsForCommand(option.options) : undefined,
default_permission: option.defaultPermission,
})
),
);
return new Collection(