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
(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
- 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!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'
Sure thing if you want.
Where are you seeing it say "any parameters passed to the constructor method are optional"? I see the data object is marked as optional.
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?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 itBut if you do this (with no parameters), that just throws an error. Unless I'm mistaken?
It shouldnt
new ChannelSelectMenuBuilder()
and new ChannelSelectMenuBuilder({})
are not the sameThis will probably resolve the problem at hand.
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.
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?
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.Correct, it isnt
But you dont have to use the constructor to set it, you can use the builder method setCustomId()
Here's the full error I receive:
Yeah if youre not setting the customId this will happen
Ohhh... I see...
at ChannelSelectMenuBuilder.toJSONThis isn't the constructor throwing, but when you try to serialize without ever setting one <:real_eyes:642875107034923008>
So because that's an alternate way to set it not via the constructor, that's optional in the constructor.
yeah
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.There's been a long standing issue about fixing the errors on builders too
Expected a string primitive but received undefined where
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 😅