fix: slash upsert bugs

This commit is contained in:
Skillz4Killz
2021-12-08 16:34:40 +00:00
committed by GitHub
parent 6d1f682538
commit 70641bbdad

View File

@@ -3,6 +3,7 @@ import type { EditGlobalApplicationCommand } from "../../../types/interactions/c
import type { MakeRequired } from "../../../types/util.ts";
import type { Bot } from "../../../bot.ts";
import { Collection } from "../../../util/collection.ts";
import { ApplicationCommandOption } from "../../../types/interactions/commands/applicationCommandOption.ts";
/**
* Bulk edit existing application commands. If a command does not exist, it will create it.
@@ -20,7 +21,13 @@ export async function upsertApplicationCommands(
guildId
? bot.constants.endpoints.COMMANDS_GUILD(bot.applicationId, guildId)
: bot.constants.endpoints.COMMANDS(bot.applicationId),
options
options.map((option) => ({
name: option.name,
description: option.description,
type: option.type,
options: option.options?.map((opt) => optionToSnakeCase(opt)),
default_permission: option.defaultPermission,
}))
);
return new Collection(
@@ -30,3 +37,21 @@ export async function upsertApplicationCommands(
})
);
}
function optionToSnakeCase(option: ApplicationCommandOption): Record<string, any> {
return {
type: option.type,
name: option.name,
description: option.description,
required: option.required,
choices: option.choices?.map((choice) => ({
name: choice.name,
value: choice.value,
})),
options: option.options?.map((o) => optionToSnakeCase(o)),
autocomplete: option.autocomplete,
channel_types: option.channelTypes,
min_value: option.minValue,
max_value: option.maxValue,
};
}