fetching command choices
hihi! i have a bit of a complicated command https://gist.github.com/ash-development/51b240f1db0e10b37994b6024263dc52
i have built this command of a previous one i built, but the main change is the team "option". i am currently getting the below error when trying to load the command:
any help would be greatly appreaciated ^~^
39 Replies
• 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.I'm guessing somehow your teamName is undefined on line 46
you could try adding a few console logs to check what exactly is going on
also I'd really recommend caching that csv, parsing it on every execution could go wrong easily
if i log the teamName in console it looks fine to me ideas on what the best way of doing that would be? 😅
just in case you could execute fetchTeamChoices() and save it to a variable outside of your builder, log that variable, and then pass it to the builder
check that there isn't an empty object or anything weird somewhere
saving it to a variable and if you want refresh it every once on a while using setInterval or with a refresh command
if it doesn't change then it's not needed
how would i go about executing it?
like uhm
where
sorry i couldn't think of the word lol
or are you just saying to do it to test it
before your exports
ah!
ope
that would probably be it
oh well it makes sense for it to return a promise
now that I notice it lol
is there a reason why you needed to wrap it on a promise?
nope not at all tbh
i didn't even give it a thought LOL
at first glance it looks like it should work without wrapping it
the only issue is the reject and resolve stuff
we have
some sort of progress
just removing the promise didn't work but this is working better?
you could probably achieve it with a callback then, but I think that'd overcomplicate it even more
the easiest way would probably be to just fetch it before registering your command, so choices is already available by the time you need it
and probably also the cleanest since it's basically caching it ^^
so basically what i did in the new gist right?
or am i misunderstanding LOL
oh yeah but you should probably throw an error instead of returning it, since that's what you had before already
like on line 56?
your callback should just have a single parameter
throw an error instead on lines 60 and 66
also instead of saving the choices you could save the entire result
and just fill choices with that
you can then just use that saved result on your run logic
okie got it got it
took a second to get my head around that LOL
hmmm im trying to figure out the best way to do that
because i also have to format it into the { name: "", value: "" } format as
do you have an example of what the object's schema looks like?
ths csv im pulling from?
or do you mean what "choices" is becoming
the csv
I mean like the object itself
okay now I see by looking at the library's npm description
you should be able to just map it since it returns an array
yeah thats why im confused on why its erroring out because its an array LOL
like is this not what you are why are you mad at
seems like it takes a single option
oh wrong one
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
If you have too many choices to display (the maximum is 25), you may prefer to provide dynamic choices based on what the user has typed so far. This can be achieved using autocomplete.me when im blind
yeah also it doesn't take an array, it's a rest parameter
it looks like this is what i need lol https://discordjs.guide/slash-commands/autocomplete.html#enabling-autocomplete
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
im completely blind
love that for me
should be .addChoices(...choices)
autocomplete would also work, take in mind that it just makes it so that your bot receives an AutocompleteInteraction when a user tries to autocomplete
you need to listen to that event and handle it (aka sort out what team the user is trying to type and respond)
got it got it
it would be much easier to use add choices but i have WAY more than 25 choices lol
yeah also now that I think of it it would be better for that refreshing logic I was mentioning before
since choices are "hardcoded" inside the command's data
you would need to update the command every time you want to add choices
which isn't really a feasible choice
you so much for your help!! ill play around with this and see what i can accomplish