Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

236
Views
Discord.JS Checking if user has role via ID strange issue

I am trying to only allow someone to do things if their permissions are correct, and currently it is just giving me this error: TypeError: Cannot read properties of undefined (reading 'has')

Here is my code:

// @ts-check

const { SlashCommandBuilder } = require('@discordjs/builders');

const userParam = "user"

module.exports = {
    data: new SlashCommandBuilder()
        .setName('checkuserskins')
        .setDescription(`Check's the selected user's custom skin inventory.`)
        .addUserOption(option =>
            option.setName("user")
                .setDescription('The user to check')
                .setRequired(true)
        ),

    async execute(interaction) {
        const user = interaction.options.getUser('user');

        if (!user) {
            return interaction.reply({ content: `Could not find user ${user}`, ephemeral: true });
        }

        if (!interaction.user.roles.has("937401230316159076") || interaction.user.id !== user.id) {
            return interaction.reply({ content: `You don't have permission to do that!`, ephemeral: true });
        }

        return interaction.reply();
    },
};

Thanks.

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

A user has no guild information. You want to get the interaction.member which has all the member's informations related to the guild.

Also, the GuildMemberRoleManager has no has method, but its cache property does.

So you need to use it like so:

interaction.member.roles.cache.has("937401230316159076")
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!