mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-15 19:08:17 +00:00
fix: typeguard for context cmds
This commit is contained in:
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user