#add command choices from array or map

1 messages · Page 1 of 1 (latest)

rotund moat
#

im trying to add the choices to a specific command from an array or map of options but cant figure out how

quasi perch
#

show the code you have so far

rotund moat
quasi perch
#

thats not valid syntax

#

what is serverConfigs?

rotund moat
#

yeah i know lol thats why im here

#

a array of arrays

quasi perch
#

when you use for..in in an array servers will be the index

#

so that wouldnt even work

#

idk what you're trying to achieve, can you show what the array looks like?

rotund moat
#

wrong sever is an arrray not an index

#

its a 2d array

quasi perch
#

so you want to add the first element of every array as the choice name and value?

rotund moat
#

yes and i see for in and of are different i didnt notice

#

so choice x = array[0], array[0]

#

for all in serverConfigs

quasi perch
#

.addChoices(...serverConfigs.map((c) => c[0]))

rotund moat
#

what is that supposed to do? it wont run

quasi perch
#

show the final code

rotund moat
quasi perch
#

you didn't close the addStringOption call

rotund moat
#

that didnt change anything

#

ZodError: [
{
"code": "invalid_type",
"expected": "array",
"received": "string",
"path": [],
"message": "Expected array, received string"
}

#

is there not a way to just add a map object as my choices

quasi perch
#

definitely changed something, given that your code didn't even run in the first place

#

ah yeah i see, mb

#

.addChoices(...serverConfigs.map((c) => [c[0], c[0]]))

rotund moat
#

lol now it just prints the error twice

#

ZodError: [
{
"code": "invalid_type",
"expected": "array",
"received": "string",
"path": [
0
],
"message": "Expected array, received string"
},
{
"code": "invalid_type",
"expected": "array",
"received": "string",
"path": [
1
],
"message": "Expected array, received string"
}
]

quasi perch
#

you're probably still using an older version of builders then, remove the ...

rotund moat
#

i installed today

quasi perch
#

yeah ignore, i was already thinking about v14

#

v13 still uses an older version of builders

rotund moat
#

wait so removing the ... worked

#

how much is gunna change in 14?

quasi perch
#

for that specific method, you'll have to use ...

rotund moat
#

ok im just worried cause 13 broke all my apps and now it seems 14 will to