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

271
Views
discord.js - guildMemberRemove no funciona, guildMemberAdd funciona perfectamente bien

Lo siento si esto está mal formateado, nunca antes había escrito una pregunta aquí.

En primer lugar, esta es la primera vez que escribo algo en JavaScript, por lo que podría ser un error tonto que estoy cometiendo y que está causando mi problema.

Lo que quiero hacer es enviar un mensaje cuando un miembro se une al servidor y enviar un mensaje diferente cuando un miembro se va. Cuando alguien se une al servidor, se envía el mensaje de unión y todo funciona perfectamente bien, pero cuando un miembro se va, no pasa absolutamente nada. Puse algunos console.logs en las funciones joinMessage y LeaveMessage, y obtengo una salida para joinMessage pero nada para eliminar. He habilitado Presence Intent y Server Members Intent en el portal para desarrolladores de Discord.

Las funciones para unir y dejar mensajes están abajo, pero seguí adelante y agregué todo para que la gente pudiera ayudarme mejor. El token de bot y los ID de canal se eliminaron y son correctos en mi versión del código.

 console.log('Starting'); const Discord = require('discord.js'); const { Client, Intents } = require('discord.js'); const commandHandler = require("./commands"); const client = new Discord.Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] }); client.login('token'); var server = client.guilds.cache.get('server'); client.on('ready', ready); function ready() { console.log('Authenticated'); server = client.guilds.cache.get('server'); } client.on('messageCreate', receivedMessage); function receivedMessage(msg) { commandHandler(msg); } client.on('guildMemberAdd', joinMessage); function joinMessage(member) { let channelWelcome = server.channels.cache.get('welcome'); let channelIntro = server.channels.cache.get('intro'); channelWelcome.send(`Welcome to the server, ${member}! Head over to ${channelIntro} and introduce yourself!`); } client.on('guildMemberRemove', leaveMessage); function leaveMessage(member) { let channelWelcome = server.channels.cache.get('welcome'); channelWelcome.send(`${member} has left the server.`); }

He estado tratando de resolver esto durante aproximadamente una hora, por lo que realmente agradecería si alguien pudiera ayudarme a resolverlo. ¡Gracias!

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

0

Debes incluir la siguiente intención: GUILD_PRESENCES

Por lo tanto, su código debe verse así:

 const client = new Discord.Client({ intents: [Intents.FLAGS.GUILD_PRESENCES, Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MEMBERS] });

Ahora tu bot detectará si un miembro deja el gremio.

about 4 years ago · Juan Pablo Isaza Report

0

Intente llamar a la función directamente en los parámetros del evento. Puede haber algún tipo de conflicto al extraer la función.

 client.on("guildMemberAdd", (member) => { let channelWelcome = server.channels.cache.get('welcome'); let channelIntro = server.channels.cache.get('intro'); channelWelcome.send(`Welcome to the server, ${member}! Head over to ${channelIntro} and introduce yourself!`); } client.on("guildMemberRemove", (member) => { let channelWelcome = server.channels.cache.get('welcome'); channelWelcome.send(`${member} has left the server.`); }

También asegúrese de haber configurado las intenciones correctas (si está ejecutando V13) y de haberle dado al bot las intenciones privilegiadas correctas en el portal para desarrolladores.

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!