How can i make an add role command

im using slash commands so how can i add a command that adds a specific role to a defined user?
client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;

//commands go here

});
client.on('interactionCreate', (interaction) => {
if (!interaction.isChatInputCommand()) return;

//commands go here

});
and i use a const commands array to register / commands
6 Replies
d.js toolkit
d.js toolkit10mo 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!
MoinAmMorgen
MoinAmMorgen10mo ago
Create the command with two required options, user name and role to add, in the interactionCreate get the user from the option and add the role from the option to the user
Zenyd
ZenydOP10mo ago
What would the code look like for thay The get user and add role
MoinAmMorgen
MoinAmMorgen10mo ago
This is a example code how you setup options
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Select a member and ban them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to ban')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for banning'))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
};
module.exports = {
data: new SlashCommandBuilder()
.setName('ban')
.setDescription('Select a member and ban them.')
.addUserOption(option =>
option
.setName('target')
.setDescription('The member to ban')
.setRequired(true))
.addStringOption(option =>
option
.setName('reason')
.setDescription('The reason for banning'))
.setDefaultMemberPermissions(PermissionFlagsBits.BanMembers)
.setDMPermission(false),
};
This explains everything pretty well
MoinAmMorgen
MoinAmMorgen10mo ago
discord.js Guide
Imagine a guide... that explores the many possibilities for your discord.js bot.
Zenyd
ZenydOP10mo ago
alr thanks ill try it
Want results from more Discord servers?
Add your server