mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-19 04:38:17 +00:00
fix(handlers): edit/upsertSlashCommand function (#441)
* fix(handlers): editSlashCommand function * this check is needed * fix(handlers): upsertSlashCommand function * fmt * add deprecated note * up * full use of options * after thinking it is better not
This commit is contained in:
+60
-18
@@ -227,27 +227,69 @@ export function getSlashCommands(guildID?: string) {
|
|||||||
/**
|
/**
|
||||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
* Edit an existing slash command. If this command did not exist, it will create it.
|
||||||
*/
|
*/
|
||||||
export function upsertSlashCommand(options: UpsertSlashCommandOptions) {
|
export function upsertSlashCommand(
|
||||||
return RequestManager.post(
|
commandID: string,
|
||||||
options.guildID
|
options: UpsertSlashCommandOptions,
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationID, options.id, options.guildID)
|
guildID?: string,
|
||||||
: endpoints.COMMANDS_ID(applicationID, options.id),
|
) {
|
||||||
{
|
// Use ... for content length due to unicode characters and js .length handling
|
||||||
...options,
|
if ([...options.name].length < 2 || [...options.name].length > 32) {
|
||||||
},
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Edit an existing slash command. */
|
if (
|
||||||
export function editSlashCommand(options: EditSlashCommandOptions) {
|
[...options.description].length < 1 || [...options.description].length > 100
|
||||||
return RequestManager.patch(
|
) {
|
||||||
options.guildID
|
throw new Error(Errors.INVALID_SLASH_DESCRIPTION);
|
||||||
? endpoints.COMMANDS_GUILD_ID(applicationID, options.id, options.guildID)
|
}
|
||||||
: endpoints.COMMANDS_ID(applicationID, options.id),
|
|
||||||
{
|
const result = RequestManager.patch(
|
||||||
...options,
|
guildID
|
||||||
},
|
? endpoints.COMMANDS_GUILD_ID(
|
||||||
|
applicationID,
|
||||||
|
guildID,
|
||||||
|
commandID,
|
||||||
|
)
|
||||||
|
: endpoints.COMMANDS_ID(applicationID, commandID),
|
||||||
|
options,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: remove this function for v11
|
||||||
|
/**
|
||||||
|
* Edit an existing slash command.
|
||||||
|
* @deprecated This function will be removed in v11. Use `upsertSlashCommand()` instead
|
||||||
|
*/
|
||||||
|
export function editSlashCommand(
|
||||||
|
commandID: string,
|
||||||
|
options: EditSlashCommandOptions,
|
||||||
|
guildID?: string,
|
||||||
|
) {
|
||||||
|
// Use ... for content length due to unicode characters and js .length handling
|
||||||
|
if ([...options.name].length < 2 || [...options.name].length > 32) {
|
||||||
|
throw new Error(Errors.INVALID_SLASH_NAME);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (
|
||||||
|
[...options.description].length < 1 || [...options.description].length > 100
|
||||||
|
) {
|
||||||
|
throw new Error(Errors.INVALID_SLASH_DESCRIPTION);
|
||||||
|
}
|
||||||
|
|
||||||
|
const result = RequestManager.patch(
|
||||||
|
guildID
|
||||||
|
? endpoints.COMMANDS_GUILD_ID(
|
||||||
|
applicationID,
|
||||||
|
guildID,
|
||||||
|
commandID,
|
||||||
|
)
|
||||||
|
: endpoints.COMMANDS_ID(applicationID, commandID),
|
||||||
|
options,
|
||||||
|
);
|
||||||
|
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Deletes a slash command. */
|
/** Deletes a slash command. */
|
||||||
|
|||||||
+14
-4
@@ -199,9 +199,15 @@ export enum InteractionResponseType {
|
|||||||
ACK_WITH_SOURCE = 5,
|
ACK_WITH_SOURCE = 5,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: remove this interface for v11
|
||||||
|
/** @deprecated Use `UpsertSlashCommandOptions` instead */
|
||||||
export interface EditSlashCommandOptions {
|
export interface EditSlashCommandOptions {
|
||||||
id: string;
|
/** 3-32 character command name */
|
||||||
guildID?: string;
|
name: string;
|
||||||
|
/** 1-100 character description */
|
||||||
|
description: string;
|
||||||
|
/** The parameters for the command */
|
||||||
|
options?: SlashCommandOption[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ExecuteSlashCommandOptions {
|
export interface ExecuteSlashCommandOptions {
|
||||||
@@ -215,6 +221,10 @@ export interface EditSlashResponseOptions extends SlashCommandCallbackData {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface UpsertSlashCommandOptions {
|
export interface UpsertSlashCommandOptions {
|
||||||
id: string;
|
/** 3-32 character command name */
|
||||||
guildID?: string;
|
name: string;
|
||||||
|
/** 1-100 character description */
|
||||||
|
description: string;
|
||||||
|
/** The parameters for the command */
|
||||||
|
options?: SlashCommandOption[];
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user