Slash Command Builder Default Option Values

Good morning all! [email protected] node v18.12.0 I'm working w/ SlashCommandBuilder and am trying to figure out how to set a default value for an option (e.g. String, Boolean, etc.) in the event the user doesn't provide a value For example,
...
.addBooleanOption(option =>
option.setName('private')
.setDescription('Post to just you or public')
...
.addBooleanOption(option =>
option.setName('private')
.setDescription('Post to just you or public')
I would want to use something like .setDefault(true) so if the user didn't give anything I could use private to do something like
const private = interaction.options.getBoolean('private')
interaction.reply({content: 'Hello there', ephemeral: private})
const private = interaction.options.getBoolean('private')
interaction.reply({content: 'Hello there', ephemeral: private})
Where it posts an ephemeral post by default unless the user explicitly sets private to false I've also tried logging the value of private with and without user input to see if I can bootleg my way around it but always get null for some reason... Any help would be appreciated! Thanks!
3 Replies
d.js toolkit
d.js toolkit15mo 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
Danial
Danial15mo ago
You can just do something like this:
const private = interaction.options.getBoolean('private') ?? true
const private = interaction.options.getBoolean('private') ?? true
Brant Goings
Brant GoingsOP15mo ago
This is perfect, can't believe I didn't think of it. Thanks @Danial 👻 !
Want results from more Discord servers?
Add your server