From fbd948003631b48a1914eb7b2551ead4b05089b7 Mon Sep 17 00:00:00 2001 From: PalmDevs Date: Sat, 12 Jul 2025 01:15:14 +0700 Subject: [PATCH] fix(bots/discord): pass non-empty out of scope label to discord --- bots/discord/src/commands/support/train/context-menu.ts | 4 +++- .../src/events/discord/interactionCreate/trainMessage.ts | 9 ++++++--- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/bots/discord/src/commands/support/train/context-menu.ts b/bots/discord/src/commands/support/train/context-menu.ts index 0eaf2a5..1aa7958 100644 --- a/bots/discord/src/commands/support/train/context-menu.ts +++ b/bots/discord/src/commands/support/train/context-menu.ts @@ -39,7 +39,7 @@ export default new Command({ custom_id: `tr_${trigger.targetMessage.channelId}_${trigger.targetId}`, options: [ ...labels.map(label => ({ label, value: label })), - { label: 'Out of scope', value: '', emoji: { name: '❌' } }, + { label: 'Out of scope', value: OutOfScopeLabel, emoji: { name: '❌' } }, ], type: ComponentType.StringSelect, } satisfies APIStringSelectComponent, @@ -51,3 +51,5 @@ export default new Command({ }) }, }) + +export const OutOfScopeLabel = '' diff --git a/bots/discord/src/events/discord/interactionCreate/trainMessage.ts b/bots/discord/src/events/discord/interactionCreate/trainMessage.ts index 5876c92..e7201da 100644 --- a/bots/discord/src/events/discord/interactionCreate/trainMessage.ts +++ b/bots/discord/src/events/discord/interactionCreate/trainMessage.ts @@ -1,4 +1,5 @@ import { MessageFlags, type TextBasedChannel } from 'discord.js' +import { OutOfScopeLabel } from '$/commands/support/train/context-menu' import { createErrorEmbed, createStackTraceEmbed, createSuccessEmbed } from '$utils/discord/embeds' import { on, withContext } from '$utils/discord/events' @@ -30,9 +31,11 @@ withContext(on, 'interactionCreate', async (context, interaction) => { flags: MessageFlags.Ephemeral, })) - // If selectedLabel is empty, it means "out of scope", so we pass undefined - const selectedLabel = interaction.values[0] || undefined - await context.api.client.trainMessage(msg.content, selectedLabel) + const selectedLabel = interaction.values[0] + await context.api.client.trainMessage( + msg.content, + selectedLabel === OutOfScopeLabel ? undefined : selectedLabel, + ) await interaction.reply({ embeds: [ createSuccessEmbed(