Skip to content

Commit

Permalink
fix: use correct regex for validating slash command names
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostdevv committed Apr 20, 2024
1 parent 869a9ba commit cb5ad6c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
5 changes: 5 additions & 0 deletions .changeset/many-items-pull.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"jellycommands": patch
---

fix: use correct regex for validating slash command names
14 changes: 5 additions & 9 deletions packages/jellycommands/src/commands/types/commands/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@ export interface CommandOptions extends BaseOptions {
}

export const commandSchema = baseCommandSchema.extend({
name: z
.string()
.min(1, 'Slash command name must be at least 1 char long')
.max(32, 'Slash command name cannot exceed 32 chars')
.regex(
/^[a-z0-9]+$/,
'Slash command name must be all lowercase, alphanumeric, and at most 32 chars long',
)
.refine((str) => str.toLowerCase() == str, 'Slash command name must be lowercase'),
name: z.string().regex(
// https://discord.com/developers/docs/interactions/application-commands#application-command-object
/^[-_\p{L}\p{N}\p{sc=Deva}\p{sc=Thai}]{1,32}$/u,
'Slash command name must be all lowercase, alphanumeric, and at most 32 chars long',
),

description: z
.string({ required_error: 'Slash command description is required' })
Expand Down

0 comments on commit cb5ad6c

Please sign in to comment.