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

160
Views
Para verificar si un usuario mencionado tiene el rol o no en discord.js

Estoy haciendo un bot de administración en discord con discord.js. Estoy tratando de hacer un comando que le dé al usuario un rol específico. Entonces quiero hacer que verifique primero si ese usuario tiene ese rol específico de antemano o no para evitar errores. El problema radica en la declaración if que verifica si el usuario tiene el rol, me da un error "Error de tipo: no se pueden leer las propiedades de undefined (leyendo 'has')". Por favor sugiérame cómo arreglar esto.

 const { Role, ThreadManager } = require("discord.js"); const ms = require('ms'); module.exports = { name: 'gulag', description: "gulag", execute(message, args) { if (message.member.permissions.has("ADMINISTRATORS")) { const target = message.mentions.users.first(); const check = message.mentions.users.first(); if (target) { let gulagRole = message.guild.roles.cache.find(role => role.name === 'gulag'); let memberTarget = message.guild.members.cache.get(target.id); if (check.roles.has(gulagRole.id)) { message.reply(`<@${memberTarget.user.id}> is already in gulag.`) } else { memberTarget.roles.add(gulagRole.id); message.channel.send(`<@${memberTarget.user.id}>`); message.channel.send('https://tenor.com/view/gulag-warzone-call-of-duty-cod-battle-royale-gif-16853559'); } } } } }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Iría directamente a message.mentions.members.first() porque esto devolverá GuildMember , por lo que es más fácil verificar los roles.

 const target = message.mentions.members.first() if(target){ if(target.roles.cache.find(r => r.name === 'gulag')){ //REST OF THE STUFF } }

Si está utilizando v13 , recuerde declarar las intenciones para su cliente también.

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!