Failure to push a slash command

const getMp3 = () => {
const allTracks = fs.readdirSync(path.join(path.resolve(), 'audio')).filter(file => file.endsWith('.mp3'));
let trackData = [];
for (const track of allTracks) {
trackData.push({
name: track.substring(0, track.length - 4),
value: track
});
}
return trackData;
}
const getMp3 = () => {
const allTracks = fs.readdirSync(path.join(path.resolve(), 'audio')).filter(file => file.endsWith('.mp3'));
let trackData = [];
for (const track of allTracks) {
trackData.push({
name: track.substring(0, track.length - 4),
value: track
});
}
return trackData;
}
I use these as choices to a slash command option
export const data = new SlashCommandBuilder()
.setName("play")
.setDescription("Plays music in a voice channel")
.addStringOption(option => {option
.setName("query")
.setDescription("The song to play")
.setRequired(true)
.addChoices(...(getMp3()));
});
export const data = new SlashCommandBuilder()
.setName("play")
.setDescription("Plays music in a voice channel")
.addStringOption(option => {option
.setName("query")
.setDescription("The song to play")
.setRequired(true)
.addChoices(...(getMp3()));
});
I get an error Djs version 14.15.3
4 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Incorecc
IncoreccOP2mo ago
C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:1469
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\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:1469:75)
at _InstanceValidator.parse (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:939:90)
at assertReturnOfBuilder (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:1620:53)
at MixedClass._sharedAddOptionMethod (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:2389:5)
at MixedClass.addStringOption (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:2360:17)
at file:///C:/Users/ADMIN/Desktop/Nexus%20Bot/commands/music/play.js:25:6
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async file:///C:/Users/ADMIN/Desktop/Nexus%20Bot/deploy_commands.js:22:19 {
validator: 's.instance(V)',
given: undefined,
expected: [Function: SlashCommandStringOption]
}

Node.js v20.15.0
C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:1469
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\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:1469:75)
at _InstanceValidator.parse (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@sapphire\shapeshift\dist\cjs\index.cjs:939:90)
at assertReturnOfBuilder (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:1620:53)
at MixedClass._sharedAddOptionMethod (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:2389:5)
at MixedClass.addStringOption (C:\Users\ADMIN\Desktop\Nexus Bot\node_modules\@discordjs\builders\dist\index.js:2360:17)
at file:///C:/Users/ADMIN/Desktop/Nexus%20Bot/commands/music/play.js:25:6
at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
at async file:///C:/Users/ADMIN/Desktop/Nexus%20Bot/deploy_commands.js:22:19 {
validator: 's.instance(V)',
given: undefined,
expected: [Function: SlashCommandStringOption]
}

Node.js v20.15.0
TÆMBØ
TÆMBØ2mo ago
You need to return the option in your addStringOption() callback or remove the curly braces
Incorecc
IncoreccOP2mo ago
Got it! I don't remember putting curly brackets and it doesn't agree with documentation
Want results from more Discord servers?
Add your server