Select menu weird bahavior

(reposted from #djs-help-v14 due to no respond for 10 minutes) Hello guys, I am back I have a problem getting my dynamic select menu mapping function to work Here's the error
[12-06-2023 12:42:22] Uncaught error
Error: Expected a string primitive
at StringValidator.handle (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@sapphire\shapeshift\dist\index.js:1715:70)
at StringValidator.parse (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at validateRequiredSelectMenuParameters (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:533:21)
at StringSelectMenuBuilder.toJSON (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:995:5)
at D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:1285:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:1285:35)
at D:\AOS\Cutie-alpha\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (D:\AOS\Cutie-alpha\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
[Error object]
{
"name": "Error",
"validator": "s.string"
}
[12-06-2023 12:42:22] Uncaught error
Error: Expected a string primitive
at StringValidator.handle (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@sapphire\shapeshift\dist\index.js:1715:70)
at StringValidator.parse (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at validateRequiredSelectMenuParameters (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:533:21)
at StringSelectMenuBuilder.toJSON (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:995:5)
at D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:1285:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (D:\AOS\Cutie-alpha\node_modules\.pnpm\@[email protected]\node_modules\@discordjs\builders\dist\index.js:1285:35)
at D:\AOS\Cutie-alpha\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (D:\AOS\Cutie-alpha\node_modules\.pnpm\[email protected]\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
[Error object]
{
"name": "Error",
"validator": "s.string"
}
And here's the function code:
33 Replies
d.js toolkit
d.js toolkit•17mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
5UP3R_D1N
5UP3R_D1N•17mo ago
const allOpt = {
claim: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Claim ticket')
.setEmoji({ name: 'closed_lock_with_key' }),
unclaim: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Unclaim ticket')
.setEmoji({ name: 'unlock' }),
close: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Close ticket')
.setEmoji({ name: 'wastebasket' }),
complete: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Complete ticket')
.setEmoji({ name: 'white_check_mark' }),
submit: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Submit result')
.setEmoji({ name: 'pen_fountain' }),
edit: new StringSelectMenuOptionBuilder()
.setLabel('Edit order')
.setEmoji({ name: 'pencil' })
};
function genActions(...options) {
return new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder().addOptions(
...options.map(
(e) =>
allOpt[e]?.setValue(e) ||
new StringSelectMenuOptionBuilder()
.setLabel('[Error] Unknown')
.setEmoji({ name: 'regional_indicator_f' })
.setValue('error404')
)
)
);
}
const allOpt = {
claim: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Claim ticket')
.setEmoji({ name: 'closed_lock_with_key' }),
unclaim: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Unclaim ticket')
.setEmoji({ name: 'unlock' }),
close: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Close ticket')
.setEmoji({ name: 'wastebasket' }),
complete: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Complete ticket')
.setEmoji({ name: 'white_check_mark' }),
submit: new StringSelectMenuOptionBuilder()
.setLabel('[Staff] Submit result')
.setEmoji({ name: 'pen_fountain' }),
edit: new StringSelectMenuOptionBuilder()
.setLabel('Edit order')
.setEmoji({ name: 'pencil' })
};
function genActions(...options) {
return new ActionRowBuilder().addComponents(
new StringSelectMenuBuilder().addOptions(
...options.map(
(e) =>
allOpt[e]?.setValue(e) ||
new StringSelectMenuOptionBuilder()
.setLabel('[Error] Unknown')
.setEmoji({ name: 'regional_indicator_f' })
.setValue('error404')
)
)
);
}
I have tried: - changing from ':emoji' to {name:'emoji'} - adding a "Unknown" option incase some are not found - my discord.js version is v14.11.0 - my node version is v18.2.0
KAVI
KAVI•17mo ago
First. Why are you spreading the object again to map it ? Second. That's a rather inefficient way to handle it.
5UP3R_D1N
5UP3R_D1N•17mo ago
what true im writing inefficient code
KAVI
KAVI•17mo ago
Third. That string select menu builder doesn't have an ID which is required
5UP3R_D1N
5UP3R_D1N•17mo ago
ohhhhhh i forgor custom_id lemme try i forgor everything in that select menu but not the options
KAVI
KAVI•17mo ago
You don't need to use the spread operator here. ... Inside the function it's a normal array that you can work with.
5UP3R_D1N
5UP3R_D1N•17mo ago
oh
KAVI
KAVI•17mo ago
But that's basic JS
5UP3R_D1N
5UP3R_D1N•17mo ago
i see that in the docs they doesnt pass an array, they pass multiple arguments of options so i did that
5UP3R_D1N
5UP3R_D1N•17mo ago
eh...
KAVI
KAVI•17mo ago
What the.... Well that's another problem in your code. A broken loop or an abused command without checks ¯\_(ツ)_/¯
5UP3R_D1N
5UP3R_D1N•17mo ago
its junk when testing
5UP3R_D1N
5UP3R_D1N•17mo ago
so i now got this error
5UP3R_D1N
5UP3R_D1N•17mo ago
which is way too large dont ask why i ping @ everyone
KAVI
KAVI•17mo ago
Looks like overlooked your emoji problem
5UP3R_D1N
5UP3R_D1N•17mo ago
h ok
KAVI
KAVI•17mo ago
Why are you using the name attribute for default emojis ?
5UP3R_D1N
5UP3R_D1N•17mo ago
lemme regex it backward
KAVI
KAVI•17mo ago
You can just pass it without having to use that .setEmoji('💖')
5UP3R_D1N
5UP3R_D1N•17mo ago
yes i dont know the cause of that error so i was thinking is it caused by this
KAVI
KAVI•17mo ago
The error was caused by the emoji mate
KAVI
KAVI•17mo ago
5UP3R_D1N
5UP3R_D1N•17mo ago
no i mean the first error
5UP3R_D1N
5UP3R_D1N•17mo ago
k i did it
5UP3R_D1N
5UP3R_D1N•17mo ago
do i need to parse emoji to unicode emoji?
KAVI
KAVI•17mo ago
It's better to do that yes Like how I did If you're in windows 11 Flag+v should give you access to all unicode emojis oh wait
5UP3R_D1N
5UP3R_D1N•17mo ago
its paste... k i found it uhh flag+v doesnt behave normally in vscode lemme do from discord
KAVI
KAVI•17mo ago
That's strange. I do it all the time from within Thonk either way works
5UP3R_D1N
5UP3R_D1N•17mo ago
done
KAVI
KAVI•17mo ago
So it worked ? Nice
5UP3R_D1N
5UP3R_D1N•17mo ago
🎉 tysm
KAVI
KAVI•17mo ago
blobguns
Want results from more Discord servers?
Add your server