Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

299
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda