Option Choices Async function.

Hi i'm trying to set my organization repos as string choices. I can use an await promise so I can't figure out how can It could be done. The code I have is this:
.addStringOption(async (option) => {
const values = await getOrgReposValues('Plasmify')
console.log(values)
return option
.setName('repositories')
.setDescription('Choose any of the organizarion repos.')
}),
.addStringOption(async (option) => {
const values = await getOrgReposValues('Plasmify')
console.log(values)
return option
.setName('repositories')
.setDescription('Choose any of the organizarion repos.')
}),
Can a async function work like that?
11 Replies
d.js toolkit
d.js toolkit12mo 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.
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Mardroide
Mardroide12mo ago
idk, the error I have is this:
return value instanceof this.expected ? Result.ok(value) : Result.err(new ExpectedValidationError("s.instance(V)", "Expected", value, this.expected));
^

ExpectedValidationError: Expected
at InstanceValidator.handle (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@sapphire\shapeshift\dist\index.js:730:75)
at InstanceValidator.parse (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at assertReturnOfBuilder (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:1441:53)
at MixedClass._sharedAddOptionMethod (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:2081:5)
at MixedClass.addStringOption (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:2052:17)
at Object.<anonymous> (C:\Users\Marcos\Documents\Work\plasma-bot\src\commands\content\repos.js:11:6)
at Module._compile (node:internal/modules/cjs/loader:1255:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at Module.load (node:internal/modules/cjs/loader:1113:32)
at Module._load (node:internal/modules/cjs/loader:960:12) {
validator: 's.instance(V)',
given: Promise { <pending> },
expected: [Function: SlashCommandStringOption]
}
return value instanceof this.expected ? Result.ok(value) : Result.err(new ExpectedValidationError("s.instance(V)", "Expected", value, this.expected));
^

ExpectedValidationError: Expected
at InstanceValidator.handle (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@sapphire\shapeshift\dist\index.js:730:75)
at InstanceValidator.parse (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@sapphire\shapeshift\dist\index.js:212:88)
at assertReturnOfBuilder (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:1441:53)
at MixedClass._sharedAddOptionMethod (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:2081:5)
at MixedClass.addStringOption (C:\Users\Marcos\Documents\Work\plasma-bot\node_modules\@discordjs\builders\dist\index.js:2052:17)
at Object.<anonymous> (C:\Users\Marcos\Documents\Work\plasma-bot\src\commands\content\repos.js:11:6)
at Module._compile (node:internal/modules/cjs/loader:1255:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1309:10)
at Module.load (node:internal/modules/cjs/loader:1113:32)
at Module._load (node:internal/modules/cjs/loader:960:12) {
validator: 's.instance(V)',
given: Promise { <pending> },
expected: [Function: SlashCommandStringOption]
}
Unknown User
Unknown User12mo ago
Message Not Public
Sign In & Join Server To View
Mardroide
Mardroide12mo ago
who's duck I have awaits at all the code 😦
duck
duck12mo ago
the addStringOption callback can't be async it's expected to return the option builder, not a Promise autocomplete would definitely be the move, or at the very least just calling <SlashCommandBuilder>.addStringOption() inside an async function and resolving it before deploying
Mardroide
Mardroide12mo ago
thanks duck do you have any example at the docs?
duck
duck12mo ago
example of what?
Mardroide
Mardroide12mo ago
autocomplete the <SlashCommandBuilder>.addStringOption()
d.js docs
d.js docs12mo ago
guide Slash Commands: Autocomplete read more
Mardroide
Mardroide12mo ago
Thanks!