How can I check user roles

So I have a slash command where the member has to mention a user in the command option, how can I get the roles from the user the member mentioned in the command to see if it has a role
6 Replies
d.js toolkit
d.js toolkit12mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
d.js docs
d.js docs12mo ago
property GuildMember#roles A manager for the roles belonging to this member
Dãrķ Søŭł
Dãrķ Søŭł12mo ago
so member.roles.cache.has(' ') would work?
royc
royc12mo ago
ideall you want to check cache first, and if it isn't cached you want to fetch
grass
grass12mo ago
fetch automatically checks cache before actually fetching
Dãrķ Søŭł
Dãrķ Søŭł12mo ago
So my slash command has the following option:
{
name: 'user',
description: 'Staff Member who get demoted',
type: ApplicationCommandOptionType.User,
required: true,
},
{
name: 'user',
description: 'Staff Member who get demoted',
type: ApplicationCommandOptionType.User,
required: true,
},
Then I take the data from the slash command option and I store it:
const user = interaction.options.getUser('user');
const user = interaction.options.getUser('user');
Then my question is how do I make it so if the user has a role the bot will continue with the command as I have set, for example if the user the staff mentions has member role it will do this otherwise nothing. @psitota If you can help anytime please let me know