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

76
Views
Comando Discord.js Ping Pong con enfriamiento

Soy muy nuevo en la codificación, así que probablemente sea horrible. aquí está el código

 let userCooldown = {}; client.on("message", message => { if (message.content.includes('ping')) if (userCooldown[message.author.id]) { userCooldown[message.author.id] = false; message.reply('Pong'); setTimeout(() => { userCooldown[message.author.id] = true; }, 5000) // 5 sec } })

el plan sería que el bot no responda el mensaje durante 5 segundos hasta que se vuelva a escribir

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

0

No estoy seguro de por qué establece el tiempo de reutilización en false si es true cuando alguien envía un mensaje y por qué lo establece en true después de cinco segundos.

Si su userCooldown incluye a los usuarios que actualmente no pueden ejecutar la función, debe verificar si ya están en esa lista. Si lo son, no ejecute la función. Si no lo están, ejecute la función, agréguelos a la lista y use setTimeout para eliminarlos después de cinco segundos. Intente ejecutar el fragmento a continuación:

 let userCooldown = {}; function onMessage(message) { console.log(`onMessage fired with message: "${message.content}"`); if (message.content.includes('ping')) { // if user can't execute the fucntion, just exit if (userCooldown[message.author.id]) return; // if they can, add them to userCooldown userCooldown[message.author.id] = true; console.log('Pong!'); // and remove them after 5 seconds setTimeout(() => { userCooldown[message.author.id] = false; }, 5000); } } // run it every second to test it :) let message = { content: '!ping', author: { id: 'authorID' } }; setInterval(() => onMessage(message), 2000)

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!