Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

237
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda