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

159
Views
Cada vez que ejecuto el bot de Discord, dice que la cantidad de miembros en línea no está definida

este es el codigo

 module.exports = async (client) => { let myGuild = client.guilds.cache.get(guild.id) setInterval(() =>{ var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size let memberCountChannel = myGuild.channels.cache.get(channel.id); console.log(onlineCount.name); memberCountChannel.setName(onlineCount + 'people online') .then(result => console.log(result)) .catch (error => console.log(error)); }, 5000) }

Y esta es la parte que cuenta los miembros

 var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size

Lo que muestra la terminal

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

0

El método de filter devuelve una matriz, y las matrices no tienen propiedad de size . Use la propiedad de length y estará bien.

Verifique también esta respuesta: https://stackoverflow.com/a/14202745/10500500

 var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").length
about 4 years ago · Juan Pablo Isaza Report

0

Dado que está reiniciando el bot, los datos no se almacenan en caché, primero debe buscar a los miembros con el método <Guild>.members.fetch . De lo contrario, significa que no activó las intenciones, consulte aquí .

Ejemplo para tu caso:

 await myGuild.members.fetch(); var onlineCount = myGuild.members.cache.filter(member => member.presence?.status != "offline").size;
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!