From b84d462ce2e2f7bb44626e53ceffaacd0ebbebab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Free=20=E5=85=AC=E5=9C=92?= <45021001+FreeAoi@users.noreply.github.com> Date: Fri, 13 Jun 2025 21:08:47 -0500 Subject: [PATCH] feat: use regex in customId component command (#345) --- 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; }