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 toolkit13mo 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
Lixeiro Charmoso13mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
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
KingBaboonOP13mo ago
What does the last 2 lines do there?
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
setDMPermission is to not allow the command be run in the bot DMs setDefaultMemberPermissions permission that is allowed to execute the command
KingBaboon
KingBaboonOP13mo ago
Ok, I get this error now?
No description
No description
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
User must be user
KingBaboon
KingBaboonOP13mo ago
Oh no caps?
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
Yes
KingBaboon
KingBaboonOP13mo ago
Ok Is there a way to make it so only certain roles can do it instead of permissions?
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
As far as i know, no. But it may be possible
KingBaboon
KingBaboonOP13mo 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
Lixeiro Charmoso13mo ago
const userToBePinged = interaction.options.getUser('user') ?? "";
KingBaboon
KingBaboonOP13mo ago
would that give me the id or what?
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
Is the user object i think Put a console.log to make sure
KingBaboon
KingBaboonOP13mo ago
how do i put a log in?
Lixeiro Charmoso
Lixeiro Charmoso13mo ago
console.log(userToBePinged)
KingBaboon
KingBaboonOP13mo ago
No description
KingBaboon
KingBaboonOP13mo ago
Aaah so how would I put the userToBePinged.id into the interaction.reply
d.js docs
d.js docs13mo 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
KingBaboonOP13mo ago
nvm figured it out sorry
teletvbis_
teletvbis_13mo ago
you can check if use has a role that can use the command in your execute
Want results from more Discord servers?
Add your server