Expected a string primitive when creating StringSelectMenu

Hello devs! caonima
Solution:
but as for the actual issue, you need to set a custom id for the StringSelectMenuBuilder
Jump to solution
5 Replies
Mercenary Ike
Mercenary IkeOP2y ago
The error is as such
[ERROR] Encountered error on chat input command "start" at path "C:\Users\tszmi\Documents\Code\EVE\src\commands\start.ts" ValidationError > s.string
Expected a string primitive

Received:
| undefined

at StringValidator.handle (C:\Users\tszmi\Documents\Code\EVE\node_modules\@sapphire\shapeshift\src\validators\StringValidator.ts:65:59)
at StringValidator.parse (C:\Users\tszmi\Documents\Code\EVE\node_modules\@sapphire\shapeshift\src\validators\BaseValidator.ts:92:2)
at validateRequiredSelectMenuParameters (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\Assertions.ts:60:20)
at StringSelectMenuBuilder.toJSON (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\selectMenu\StringSelectMenu.ts:142:3)
at map (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\ActionRow.ts:113:61)
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\ActionRow.ts:113:32)
at C:\Users\tszmi\Documents\Code\EVE\node_modules\discord.js\src\structures\MessagePayload.js:137:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (C:\Users\tszmi\Documents\Code\EVE\node_modules\discord.js\src\structures\MessagePayload.js:137:49)
[ERROR] Encountered error on chat input command "start" at path "C:\Users\tszmi\Documents\Code\EVE\src\commands\start.ts" ValidationError > s.string
Expected a string primitive

Received:
| undefined

at StringValidator.handle (C:\Users\tszmi\Documents\Code\EVE\node_modules\@sapphire\shapeshift\src\validators\StringValidator.ts:65:59)
at StringValidator.parse (C:\Users\tszmi\Documents\Code\EVE\node_modules\@sapphire\shapeshift\src\validators\BaseValidator.ts:92:2)
at validateRequiredSelectMenuParameters (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\Assertions.ts:60:20)
at StringSelectMenuBuilder.toJSON (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\selectMenu\StringSelectMenu.ts:142:3)
at map (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\ActionRow.ts:113:61)
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (C:\Users\tszmi\Documents\Code\EVE\node_modules\@discordjs\builders\src\components\ActionRow.ts:113:32)
at C:\Users\tszmi\Documents\Code\EVE\node_modules\discord.js\src\structures\MessagePayload.js:137:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (C:\Users\tszmi\Documents\Code\EVE\node_modules\discord.js\src\structures\MessagePayload.js:137:49)
I suspect this is the area where this error comes up
public static GetInteraction(channelID: string) {
const actionRow = new ActionRowBuilder<StringSelectMenuBuilder>()
.addComponents( new StringSelectMenuBuilder()
.addOptions([
// ...tactics,
new StringSelectMenuOptionBuilder()
.setLabel('label')
.setEmoji('🛡️')
.setLabel("Hold")
.setDescription("description")
.setValue("hold"),
new StringSelectMenuOptionBuilder()
.setLabel('label')
.setEmoji('🙇')
.setLabel("Recover")
.setDescription("description")
.setValue("recover")
]))

console.log("Action row built:", actionRow.components[0].options)
return { embeds: [this.GetCurrentStatusEmbed(channelID)], components: [actionRow] };
}
public static GetInteraction(channelID: string) {
const actionRow = new ActionRowBuilder<StringSelectMenuBuilder>()
.addComponents( new StringSelectMenuBuilder()
.addOptions([
// ...tactics,
new StringSelectMenuOptionBuilder()
.setLabel('label')
.setEmoji('🛡️')
.setLabel("Hold")
.setDescription("description")
.setValue("hold"),
new StringSelectMenuOptionBuilder()
.setLabel('label')
.setEmoji('🙇')
.setLabel("Recover")
.setDescription("description")
.setValue("recover")
]))

console.log("Action row built:", actionRow.components[0].options)
return { embeds: [this.GetCurrentStatusEmbed(channelID)], components: [actionRow] };
}
Favna
Favna2y ago
for starters you're setting the label twice
Solution
Favna
Favna2y ago
but as for the actual issue, you need to set a custom id for the StringSelectMenuBuilder
Favna
Favna2y ago
const actionRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder() //
.setCustomId('insert-custom-id-here')
.setOptions([
// ...tactics,
new StringSelectMenuOptionBuilder() //
.setEmoji('🛡️')
.setLabel('Hold')
.setDescription('description')
.setValue('hold'),
new StringSelectMenuOptionBuilder() //
.setEmoji('🙇')
.setLabel('Recover')
.setDescription('description')
.setValue('recover')
])
);
const actionRow = new ActionRowBuilder<StringSelectMenuBuilder>().addComponents(
new StringSelectMenuBuilder() //
.setCustomId('insert-custom-id-here')
.setOptions([
// ...tactics,
new StringSelectMenuOptionBuilder() //
.setEmoji('🛡️')
.setLabel('Hold')
.setDescription('description')
.setValue('hold'),
new StringSelectMenuOptionBuilder() //
.setEmoji('🙇')
.setLabel('Recover')
.setDescription('description')
.setValue('recover')
])
);
Want results from more Discord servers?
Add your server