Components falsely listed as optional?

In the documentation for ChannelSelectMenuBuilder, it says any parameters passed to the constructor method are optional. However, when I try to create a ChannelSelectMenuBuilder without any parameters at all (e.g. like const channelSelect = new ChannelSelectMenuBuilder({}); ) then Discord.js throws the error
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle
etc...
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle
etc...
(Passing the custom_id property in the parameter immediately fixes this.) So it doesn't seem like these parameters are completely optional if you can't construct a ChannelSelectMenuBuilder without any of them?
builders | ChannelSelectMenuBuilder
Discord.js API Documentation
22 Replies
d.js toolkit
d.js toolkit14mo 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!
monbrey
monbrey14mo ago
If you're going to pass an object, then certain properties in that object are required I think Can you provide the full error and not 'etc'
2Flow2
2Flow2OP14mo ago
Sure thing if you want.
monbrey
monbrey14mo ago
Where are you seeing it say "any parameters passed to the constructor method are optional"? I see the data object is marked as optional.
2Flow2
2Flow2OP14mo ago
The required property is custom_id. The issue is not that I am have an error I don't know how to solve. The issue is that I'm confused why the documentation page says the data parameter is marked optional if you have to use it to pass the custom_id property?
monbrey
monbrey14mo ago
You dont have to use it It's optional, therefore you can do new ChannelSelectMenuBuilder() But if you do choose to use it, then it requires that you pass custom_id in it
2Flow2
2Flow2OP14mo ago
But if you do this (with no parameters), that just throws an error. Unless I'm mistaken?
monbrey
monbrey14mo ago
It shouldnt new ChannelSelectMenuBuilder() and new ChannelSelectMenuBuilder({}) are not the same
space
space14mo ago
This will probably resolve the problem at hand.
2Flow2
2Flow2OP14mo ago
Okay, fair. I was doing the former and then switched to the latter while debugging. They were throwing identical errors so that's by bad for assuming they were the same. Okay sure thing, lemme grab it.
monbrey
monbrey14mo ago
I mean, you will have to set a custom id one way or the other before you use it So possibly the constructor parameter was never the issue at all Is that what your question actually meant and I misunderstood?
2Flow2
2Flow2OP14mo ago
Yeah. Apologies, what I was trying to say is that if you have to set a custom_id before you can use the ChannelSelectMenuBuilder without an error being thrown, then custom_id (or more specifically, the parameter object it goes in) doesn't feel very "optional" at all.
monbrey
monbrey14mo ago
Correct, it isnt But you dont have to use the constructor to set it, you can use the builder method setCustomId()
2Flow2
2Flow2OP14mo ago
Here's the full error I receive:
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (D:\Soma Projects\SomaBot\trunk\node_modules\@sapphire\shapeshift\dist\index.js:1742:70)
at _StringValidator.parse (D:\Soma Projects\SomaBot\trunk\node_modules\@sapphire\shapeshift\dist\index.js:216:88)
at ChannelSelectMenuBuilder.toJSON (D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:827:23)
at D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:1310:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:1310:35)
at D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
at InteractionWebhook.send (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\Webhook.js:213:61)
node:events:491
throw er; // Unhandled 'error' event
^

Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.reply (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102:46)
at Client.<anonymous> (D:\Soma Projects\SomaBot\trunk\index.js:213:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
code: 'InteractionAlreadyReplied'
}

Node.js v18.7.0
ValidationError > s.string
Expected a string primitive

Received:
| undefined

at _StringValidator.handle (D:\Soma Projects\SomaBot\trunk\node_modules\@sapphire\shapeshift\dist\index.js:1742:70)
at _StringValidator.parse (D:\Soma Projects\SomaBot\trunk\node_modules\@sapphire\shapeshift\dist\index.js:216:88)
at ChannelSelectMenuBuilder.toJSON (D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:827:23)
at D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:1310:64
at Array.map (<anonymous>)
at ActionRowBuilder.toJSON (D:\Soma Projects\SomaBot\trunk\node_modules\@discordjs\builders\dist\index.js:1310:35)
at D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\MessagePayload.js:136:109
at Array.map (<anonymous>)
at MessagePayload.resolveBody (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\MessagePayload.js:136:49)
at InteractionWebhook.send (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\Webhook.js:213:61)
node:events:491
throw er; // Unhandled 'error' event
^

Error [InteractionAlreadyReplied]: The reply to this interaction has already been sent or deferred.
at ChatInputCommandInteraction.reply (D:\Soma Projects\SomaBot\trunk\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:102:46)
at Client.<anonymous> (D:\Soma Projects\SomaBot\trunk\index.js:213:21)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
Emitted 'error' event on Client instance at:
at emitUnhandledRejectionOrErr (node:events:394:10)
at process.processTicksAndRejections (node:internal/process/task_queues:84:21) {
code: 'InteractionAlreadyReplied'
}

Node.js v18.7.0
monbrey
monbrey14mo ago
Yeah if youre not setting the customId this will happen
2Flow2
2Flow2OP14mo ago
Ohhh... I see...
space
space14mo ago
at ChannelSelectMenuBuilder.toJSON
This isn't the constructor throwing, but when you try to serialize without ever setting one <:real_eyes:642875107034923008>
2Flow2
2Flow2OP14mo ago
So because that's an alternate way to set it not via the constructor, that's optional in the constructor.
monbrey
monbrey14mo ago
yeah
2Flow2
2Flow2OP14mo ago
Okay, that makes sense. I wish there was a way to indicate in the documentation that a custom_id parameter is necessary. That wasn't immediately obvious to me from reading the docs and I spent a good while trying to track down why that was breaking.
monbrey
monbrey14mo ago
There's been a long standing issue about fixing the errors on builders too Expected a string primitive but received undefined where
2Flow2
2Flow2OP14mo ago
Yeah... exactly. If there's any way I can be in service of helping solve this problem so others don't have to encounter it as frequently, let me know 😅
Want results from more Discord servers?
Add your server