Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

297
Vistas
SyntaxError: await is only valid in async functions and the top level bodies of modules. Discord,js

Error:

SyntaxError: await is only valid in async functions and the top level bodies of modules

[Photo error] https://i.stack.imgur.com/a0hWM.png

const client = require('../index.js');

client.on('ready', () => {
  let servers = await client.guilds.cache.size
  let servercount = await client.guilds.cache.reduce((a,b) => a+b.memberCount, 0)

  const activites = [
    `?help | ${servers} servers`,
    `Invite me now! | Watching ${servercount} members`
  ]

  setInterval(()=>{
    const status = activities[Math.floor(Math.random()*activities.length)]
    client.user.setPresence({ activities : [{name : `${status}`}]})
  }, 5000)

  
  console.log(`✅ ${client.user.tag} is ready`)
})
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You can use await with only async functions. Checkout the below code where I have changed your client.on callback function to async.

const client = require('../index.js');

client.on('ready', async() => {
  let servers = await client.guilds.cache.size
  let servercount = await client.guilds.cache.reduce((a,b) => a+b.memberCount, 0)

  const activites = [
    `?help | ${servers} servers`,
    `Invite me now! | Watching ${servercount} members`
  ]

  setInterval(()=>{
    const status = activities[Math.floor(Math.random()*activities.length)]
    client.user.setPresence({ activities : [{name : `${status}`}]})
  }, 5000)

  
  console.log(`✅ ${client.user.tag} is ready`)
})

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda