How to add options to a slash command?

How would I add options for people to input data when making a slash command? This is what I have so far.
No description
22 Replies
d.js toolkit
d.js toolkit6mo 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!
Lixeiro Charmoso
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Lixeiro Charmoso
new SlashCommandBuilder()
.setName('docs')
.setDescription('Read the docs message')
.addUserOption(option =>
option.setName('target')
.setDescription('Ping the user')
.setRequired(false))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
new SlashCommandBuilder()
.setName('docs')
.setDescription('Read the docs message')
.addUserOption(option =>
option.setName('target')
.setDescription('Ping the user')
.setRequired(false))
.setDefaultMemberPermissions(PermissionFlagsBits.ManageRoles)
.setDMPermission(false),
KingBaboon
KingBaboon6mo ago
What does the last 2 lines do there?
Lixeiro Charmoso
setDMPermission is to not allow the command be run in the bot DMs setDefaultMemberPermissions permission that is allowed to execute the command
KingBaboon
KingBaboon6mo ago
Ok, I get this error now?
No description
No description
Lixeiro Charmoso
User must be user
KingBaboon
KingBaboon6mo ago
Oh no caps?
Lixeiro Charmoso
Yes
KingBaboon
KingBaboon6mo ago
Ok Is there a way to make it so only certain roles can do it instead of permissions?
Lixeiro Charmoso
As far as i know, no. But it may be possible
KingBaboon
KingBaboon6mo ago
Ok, how would I now get the user that they inputted when it replies, for example pinging them in the ping message.
No description
Lixeiro Charmoso
const userToBePinged = interaction.options.getUser('user') ?? "";
KingBaboon
KingBaboon6mo ago
would that give me the id or what?
Lixeiro Charmoso
Is the user object i think Put a console.log to make sure
KingBaboon
KingBaboon6mo ago
how do i put a log in?
Lixeiro Charmoso
console.log(userToBePinged)
KingBaboon
KingBaboon6mo ago
No description
KingBaboon
KingBaboon6mo ago
Aaah so how would I put the userToBePinged.id into the interaction.reply
d.js docs
d.js docs6mo ago
mdn Template literals (Template strings) Template literals are literals delimited with backtick (`) characters, allowing for multi-line strings, string interpolation with embedded expressions, and special constructs called tagged templates.
KingBaboon
KingBaboon6mo ago
nvm figured it out sorry
teletvbis_
teletvbis_6mo ago
you can check if use has a role that can use the command in your execute