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:
CombinedPropertyError (1)
Received one or more errors

input[0]
| CombinedPropertyError (2)
| Received one or more errors
|
| input.name
| | MissingPropertyError > name
| | A required property is missing
|
| input.value
| | MissingPropertyError > value
| | A required property is missing

at ArrayValidator.handle (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@sapphire\shapeshift\dist\index.js:473:70)
at ArrayValidator.parse (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at MixedClass.addChoices (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:1763:22)
at C:\Users\Ty\IdeaProjects\mainBot\src\commands\team.js:16:18
at MixedClass._sharedAddOptionMethod (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:2080:50)
at MixedClass.addStringOption (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:2052:17)
at Object.<anonymous> (C:\Users\Ty\IdeaProjects\mainBot\src\commands\team.js:11:10)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
CombinedPropertyError (1)
Received one or more errors

input[0]
| CombinedPropertyError (2)
| Received one or more errors
|
| input.name
| | MissingPropertyError > name
| | A required property is missing
|
| input.value
| | MissingPropertyError > value
| | A required property is missing

at ArrayValidator.handle (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@sapphire\shapeshift\dist\index.js:473:70)
at ArrayValidator.parse (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at MixedClass.addChoices (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:1763:22)
at C:\Users\Ty\IdeaProjects\mainBot\src\commands\team.js:16:18
at MixedClass._sharedAddOptionMethod (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:2080:50)
at MixedClass.addStringOption (C:\Users\Ty\IdeaProjects\mainBot\node_modules\@discordjs\builders\dist\index.js:2052:17)
at Object.<anonymous> (C:\Users\Ty\IdeaProjects\mainBot\src\commands\team.js:11:10)
at Module._compile (node:internal/modules/cjs/loader:1159:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1213:10)
at Module.load (node:internal/modules/cjs/loader:1037:32)
any help would be greatly appreaciated ^~^
Gist
team.js
GitHub Gist: instantly share code, notes, and snippets.
39 Replies
d.js toolkit
d.js toolkit2y 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.
Amgelo
Amgelo2y ago
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
ashie
ashieOP2y ago
if i log the teamName in console it looks fine to me Hmmge ideas on what the best way of doing that would be? 😅
Amgelo
Amgelo2y ago
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
ashie
ashieOP2y ago
Hmmge 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
Amgelo
Amgelo2y ago
before your exports
const choices = fetchTeamChoices();
console.log(choices);

module.exports = {
data: new SlashCommandBuilder()
.setName("teamrank")
.setDescription("View the rank of a team.")
.addStringOption((option) =>
option
.setName("team")
.setDescription("Select a team from the list.")
.setRequired(true)
.addChoices(choices)
),
run: async (client, interaction) => {
// etc
const choices = fetchTeamChoices();
console.log(choices);

module.exports = {
data: new SlashCommandBuilder()
.setName("teamrank")
.setDescription("View the rank of a team.")
.addStringOption((option) =>
option
.setName("team")
.setDescription("Select a team from the list.")
.setRequired(true)
.addChoices(choices)
),
run: async (client, interaction) => {
// etc
ashie
ashieOP2y ago
ah! ope
Promise { <pending> }
Promise { <pending> }
that would probably be it skiestThinking
Amgelo
Amgelo2y ago
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?
ashie
ashieOP2y ago
nope not at all tbh i didn't even give it a thought LOL
Amgelo
Amgelo2y ago
at first glance it looks like it should work without wrapping it
ashie
ashieOP2y ago
the only issue is the reject and resolve stuff
ashie
ashieOP2y ago
Gist
new team.js
GitHub Gist: instantly share code, notes, and snippets.
ashie
ashieOP2y ago
we have some sort of progress just removing the promise didn't work but this is working better?
ashie
ashieOP2y ago
Amgelo
Amgelo2y ago
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 ^^
ashie
ashieOP2y ago
so basically what i did in the new gist right? or am i misunderstanding LOL
Amgelo
Amgelo2y ago
oh yeah but you should probably throw an error instead of returning it, since that's what you had before already
ashie
ashieOP2y ago
like on line 56?
Amgelo
Amgelo2y ago
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
ashie
ashieOP2y ago
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 Hmmge
Amgelo
Amgelo2y ago
do you have an example of what the object's schema looks like?
ashie
ashieOP2y ago
ths csv im pulling from? or do you mean what "choices" is becoming
Amgelo
Amgelo2y ago
the csv
ashie
ashieOP2y ago
Amgelo
Amgelo2y ago
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
ashie
ashieOP2y ago
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 KekDoge
d.js docs
d.js docs2y ago
Amgelo
Amgelo2y ago
seems like it takes a single option oh wrong one
ashie
ashieOP2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
d.js docs
d.js docs2y ago
method SlashCommandIntegerOption#addChoices() Adds multiple choices for this option
ashie
ashieOP2y ago
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
Amgelo
Amgelo2y ago
yeah also it doesn't take an array, it's a rest parameter
ashie
ashieOP2y ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
ashie
ashieOP2y ago
im completely blind love that for me
Amgelo
Amgelo2y ago
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)
ashie
ashieOP2y ago
got it got it it would be much easier to use add choices but i have WAY more than 25 choices lol
Amgelo
Amgelo2y ago
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
ashie
ashieOP2y ago
swagyes you so much for your help!! ill play around with this and see what i can accomplish
Amgelo
Amgelo2y ago
duckthumbsup
Want results from more Discord servers?
Add your server