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

303
Views
discord.js no puede agregar un rol a un miembro cuando se une a mi servidor

Quiero que mi bot otorgue un cierto rol a las personas cuando se unan al servidor. Pero recibo un error extraño que realmente no entiendo.

Este es el código:

 const { GuildMember, MessageEmbed } = require("discord.js"); module.exports = { name: "guildMemberAdd", /** * @param {GuildMember} member */ async execute(member){ let role = member.guild.roles.cache.some(role => role.name === 'Member') member.roles.add(role) member.guild.channels.cache.get(process.env.WELCOME_MESSAGE_CHANNEL_ID).send({ embeds: [ new MessageEmbed() .setTitle("Welcome! :smiley:") .setDescription(`${member.toString()} has joined the server!\n Thanks for joining. Head over to <#${process.env.RULE_CHANNEL_ID}> and verify yourself in <#${process.env.VERIFY_CHANNEL_ID}> to get access to all other channels.`) .setThumbnail(member.user.displayAvatarURL()) .setColor("GREEN") ] }) } }

Y cuando alguien se une me sale este mensaje de error:

TypeError [INVALID_TYPE]: los roles proporcionados no son un rol, un copo de nieve, una matriz, una colección de roles o un copo de nieve.

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

0

El problema es que some() devuelve un booleano (ya sea true o false ) y cuando intenta agregar un rol al miembro, pasa este valor booleano en lugar de una ID de rol. En su lugar, puede usar el método find() que devuelve el primer elemento donde la función dada devuelve un valor verdadero (es decir, donde role.name es igual a "Member" ):

 async execute(member) { let role = member.guild.roles.cache.find((role) => role.name === 'Member'); if (!role) return console.log('Cannot find the role with the name "Member"'); member.roles.add(role); member.guild.channels.cache .get(process.env.WELCOME_MESSAGE_CHANNEL_ID) .send({ embeds: [ new MessageEmbed() .setTitle('Welcome! :smiley:') .setDescription( `${member.toString()} has joined the server!\n Thanks for joining. Head over to <#${process.env.RULE_CHANNEL_ID}> and verify yourself in <#${process.env.VERIFY_CHANNEL_ID}> to get access to all other channels.`, ) .setThumbnail(member.user.displayAvatarURL()) .setColor('GREEN'), ], }); }
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!