mirror of
https://github.com/discordeno/discordeno.git
synced 2026-06-03 17:30:07 +00:00
fix(plugins): createApplicationCommand validation
This commit is contained in:
@@ -92,6 +92,41 @@ export function createApplicationCommand(bot: BotWithCache) {
|
||||
|
||||
// Only slash need to be lowercase
|
||||
options.name = options.name.toLowerCase();
|
||||
|
||||
// Slash commands require description
|
||||
if (
|
||||
!options.description &&
|
||||
(isChatInput)
|
||||
) {
|
||||
throw new Error(
|
||||
"Slash commands require some form of a description be provided.",
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
options.description &&
|
||||
((options.type === ApplicationCommandTypes.User) ||
|
||||
(options.type === ApplicationCommandTypes.Message))
|
||||
) {
|
||||
throw new Error("Context menu commands do not allow a description.");
|
||||
}
|
||||
|
||||
if (
|
||||
options.description &&
|
||||
!bot.utils.validateLength(options.description, { min: 1, max: 100 })
|
||||
) {
|
||||
throw new Error(
|
||||
"Application command descriptions must be between 1 and 100 characters.",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.options?.length) {
|
||||
if (options.options.length > 25) {
|
||||
throw new Error("Only 25 options are allowed to be provided.");
|
||||
}
|
||||
|
||||
options.options = validateApplicationCommandOptions(bot, options.options);
|
||||
}
|
||||
} else {
|
||||
if (!CONTEXT_MENU_COMMANDS_NAME_REGEX.test(options.name)) {
|
||||
throw new Error(
|
||||
@@ -100,41 +135,6 @@ export function createApplicationCommand(bot: BotWithCache) {
|
||||
}
|
||||
}
|
||||
|
||||
// Slash commands require description
|
||||
if (
|
||||
!options.description &&
|
||||
(isChatInput)
|
||||
) {
|
||||
throw new Error(
|
||||
"Slash commands require some form of a description be provided.",
|
||||
);
|
||||
}
|
||||
|
||||
if (
|
||||
options.description &&
|
||||
((options.type === ApplicationCommandTypes.User) ||
|
||||
(options.type === ApplicationCommandTypes.Message))
|
||||
) {
|
||||
throw new Error("Context menu commands do not allow a description.");
|
||||
}
|
||||
|
||||
if (
|
||||
options.description &&
|
||||
!bot.utils.validateLength(options.description, { min: 1, max: 100 })
|
||||
) {
|
||||
throw new Error(
|
||||
"Application command descriptions must be between 1 and 100 characters.",
|
||||
);
|
||||
}
|
||||
|
||||
if (options.options?.length) {
|
||||
if (options.options.length > 25) {
|
||||
throw new Error("Only 25 options are allowed to be provided.");
|
||||
}
|
||||
|
||||
options.options = validateApplicationCommandOptions(bot, options.options);
|
||||
}
|
||||
|
||||
return await createApplicationCommandOld(options, guildId);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user