From 8472917a7c57c5283f2ab0a2cb52c883796f56fd Mon Sep 17 00:00:00 2001 From: FreeAoi Date: Fri, 13 Jun 2025 20:01:07 -0600 Subject: [PATCH] feat: use regex in customId component command --- src/components/componentcommand.ts | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/components/componentcommand.ts b/src/components/componentcommand.ts index be2989b..55408da 100644 --- a/src/components/componentcommand.ts +++ b/src/components/componentcommand.ts @@ -14,13 +14,18 @@ export interface ComponentCommand { export abstract class ComponentCommand { type = InteractionCommandType.COMPONENT; abstract componentType: keyof ContextComponentCommandInteractionMap; - customId?: string; + customId?: string | RegExp; filter?(context: ComponentContext): Promise | boolean; abstract run(context: ComponentContext): any; /** @internal */ _filter(context: ComponentContext) { - if (this.customId && this.customId !== context.customId) return false; + if (this.customId) { + const isString = typeof this.customId === 'string'; + const matches = isString ? this.customId === context.customId : (this.customId as RegExp).test(context.customId); + + if (!matches) return false; + } if (this.filter) return this.filter(context); return true; }