mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-16 19:28: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:
+59
-17
@@ -227,27 +227,69 @@ export function getSlashCommands(guildID?: string) {
|
||||
/**
|
||||
* Edit an existing slash command. If this command did not exist, it will create it.
|
||||
*/
|
||||
export function upsertSlashCommand(options: UpsertSlashCommandOptions) {
|
||||
return RequestManager.post(
|
||||
options.guildID
|
||||
? endpoints.COMMANDS_GUILD_ID(applicationID, options.id, options.guildID)
|
||||
: endpoints.COMMANDS_ID(applicationID, options.id),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
export function upsertSlashCommand(
|
||||
commandID: string,
|
||||
options: UpsertSlashCommandOptions,
|
||||
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;
|
||||
}
|
||||
|
||||
/** Edit an existing slash command. */
|
||||
export function editSlashCommand(options: EditSlashCommandOptions) {
|
||||
return RequestManager.patch(
|
||||
options.guildID
|
||||
? endpoints.COMMANDS_GUILD_ID(applicationID, options.id, options.guildID)
|
||||
: endpoints.COMMANDS_ID(applicationID, options.id),
|
||||
{
|
||||
...options,
|
||||
},
|
||||
// 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. */
|
||||
|
||||
Reference in New Issue
Block a user