mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-19 04:38:17 +00:00
feat(handlers): add upsertSlashCommands() (#442)
* feat(handlers): add bulk upsert commands function * Update mod.ts * add jsdoc * add ID info * ID is optional * Update webhook.ts * use //@ts-ignore * idk
This commit is contained in:
@@ -120,6 +120,7 @@ import {
|
|||||||
getSlashCommands,
|
getSlashCommands,
|
||||||
getWebhook,
|
getWebhook,
|
||||||
upsertSlashCommand,
|
upsertSlashCommand,
|
||||||
|
upsertSlashCommands,
|
||||||
} from "./webhook.ts";
|
} from "./webhook.ts";
|
||||||
|
|
||||||
export let handlers = {
|
export let handlers = {
|
||||||
@@ -241,6 +242,7 @@ export let handlers = {
|
|||||||
getSlashCommand,
|
getSlashCommand,
|
||||||
getSlashCommands,
|
getSlashCommands,
|
||||||
upsertSlashCommand,
|
upsertSlashCommand,
|
||||||
|
upsertSlashCommands,
|
||||||
editSlashCommand,
|
editSlashCommand,
|
||||||
deleteSlashCommand,
|
deleteSlashCommand,
|
||||||
executeSlashCommand,
|
executeSlashCommand,
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ import {
|
|||||||
MessageCreateOptions,
|
MessageCreateOptions,
|
||||||
SlashCommand,
|
SlashCommand,
|
||||||
UpsertSlashCommandOptions,
|
UpsertSlashCommandOptions,
|
||||||
|
UpsertSlashCommandsOptions,
|
||||||
WebhookCreateOptions,
|
WebhookCreateOptions,
|
||||||
WebhookPayload,
|
WebhookPayload,
|
||||||
} from "../../types/mod.ts";
|
} from "../../types/mod.ts";
|
||||||
@@ -270,6 +271,40 @@ export function upsertSlashCommand(
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Bulk edit existing slash commands. If a command does not exist, it will create it.
|
||||||
|
*
|
||||||
|
* **NOTE:** Any slash commands that are not specified in this function will be **deleted**. If you don't provide the commandID and rename your command, the command gets a new ID.
|
||||||
|
*/
|
||||||
|
export async function upsertSlashCommands(
|
||||||
|
options: UpsertSlashCommandsOptions[],
|
||||||
|
guildID?: string,
|
||||||
|
) {
|
||||||
|
const data = options.map((option) => {
|
||||||
|
// Use ... for content length due to unicode characters and js .length handling
|
||||||
|
if ([...option.name].length < 2 || [...option.name].length > 32) {
|
||||||
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
[...option.description].length < 1 || [...option.description].length > 100
|
||||||
|
) {
|
||||||
|
throw new Error(Errors.INVALID_SLASH_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
return option;
|
||||||
|
});
|
||||||
|
|
||||||
|
const result = await RequestManager.put(
|
||||||
|
guildID
|
||||||
|
? endpoints.COMMANDS_GUILD(applicationID, guildID)
|
||||||
|
: endpoints.COMMANDS(applicationID),
|
||||||
|
data,
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO: remove this function for v11
|
// TODO: remove this function for v11
|
||||||
/**
|
/**
|
||||||
* Edit an existing slash command.
|
* Edit an existing slash command.
|
||||||
|
|||||||
@@ -228,3 +228,14 @@ export interface UpsertSlashCommandOptions {
|
|||||||
/** The parameters for the command */
|
/** The parameters for the command */
|
||||||
options?: SlashCommandOption[];
|
options?: SlashCommandOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface UpsertSlashCommandsOptions {
|
||||||
|
/** The id of the command */
|
||||||
|
id: string;
|
||||||
|
/** 3-32 character command name */
|
||||||
|
name: string;
|
||||||
|
/** 1-100 character description */
|
||||||
|
description: string;
|
||||||
|
/** The parameters for the command */
|
||||||
|
options?: SlashCommandOption[];
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user