How do I add a role with discord.js

const target = interaction.options.getUser('target');
const role = interaction.options.getRole('role');
target.addRole(role);
const target = interaction.options.getUser('target');
const role = interaction.options.getRole('role');
target.addRole(role);
is this how i add the role?
3 Replies
d.js toolkit
d.js toolkit4mo 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
Danial4mo ago
Users don't have roles, members do, change that getUser() to getMember() and it'd be target.roles.add(role)
paxton!!
paxton!!4mo ago
thank you! i will mark as solved