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

211
Vistas
Discord.js forms

I'm trying to make a forms but it doesn't work well for me. The timeout does not work and I need to type the command twice for it to work I don't know why

const Discord = require('discord.js');


module.exports = {
    name: 'forms',
    category: "Info",
    description: 'forms',
    run: async(client, message, args) => {
        const questions = [                   
        "What's your IGN?",                  
        "How old are you?",                 
        "What time zone do you reside in?", 
        "Do you have Schematica?"            
      ];                                     
      
      const applying = [];
      
      bot.on("messageCreate", async message => {
        if (message.author.bot) return;
      
        if (message.content.toLowerCase() === "!forms") {
          if (applying.includes(message.author.id)) return;
      
          try {
            console.log(`${message.author.tag} began applying.`);
      
            applying.push(message.author.id);
            await message.author.send(":pencil: **Application started!** Type `#cancel` to exit.");
      
            for (let i = 0, cancel = false; i < questions.length && cancel === false; i++) {
              await message.author.send(questions[i]);
              await message.author.send(m => m.author.id === message.author.id, { max: 1, time: 300000, errors: ["time"] })
                .then(async collected => {
                  if (collected.first().content.toLowerCase() === "#cancel") {
                    await message.channel.send(":x: **Application cancelled.**");
                    applying.splice(applying.indexOf(message.author.id), 1);
                    cancel = true;
      
                    console.log(`${message.author.tag} cancelled their application.`);
                  }
                }).catch(async ()=> {
                  await message.author.send(":hourglass: **Application timed out.**");
                  applying.splice(applying.indexOf(message.author.id), 1);
                  cancel = true;
      
                  console.log(`${message.author.tag} let their application time out.`);
                });
            }
      
            await message.author.send(":thumbsup: **You're all done!**");
      
            console.log(`${message.author.tag} finished applying.`);
          } catch(err) {
            console.error(err);
          }
        }
      });
      
      
   
    },
};
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

Remove the messageCreate event from there:

const questions = [                   
        "What's your IGN?",                  
        "How old are you?",                 
        "What time zone do you reside in?", 
        "Do you have Schematica?"            
      ];                                     
      
      const applying = [];
        if (message.author.bot) return;
      
        if (message.content.toLowerCase() === "!forms") {
          if (applying.includes(message.author.id)) return;
      
          try {
            console.log(`${message.author.tag} began applying.`);
      
            applying.push(message.author.id);
            await message.author.send(":pencil: **Application started!** Type `#cancel` to exit.");
      
            for (let i = 0, cancel = false; i < questions.length && cancel === false; i++) {
              await message.author.send(questions[i]);
              await message.author.send(m => m.author.id === message.author.id, { max: 1, time: 300000, errors: ["time"] })
                .then(async collected => {
                  if (collected.first().content.toLowerCase() === "#cancel") {
                    await message.channel.send(":x: **Application cancelled.**");
                    applying.splice(applying.indexOf(message.author.id), 1);
                    cancel = true;
      
                    console.log(`${message.author.tag} cancelled their application.`);
                  }
                }).catch(async ()=> {
                  await message.author.send(":hourglass: **Application timed out.**");
                  applying.splice(applying.indexOf(message.author.id), 1);
                  cancel = true;
      
                  console.log(`${message.author.tag} let their application time out.`);
                });
            }
      
            await message.author.send(":thumbsup: **You're all done!**");
      
            console.log(`${message.author.tag} finished applying.`);
          } catch(err) {
            console.error(err);
          }
        }

Note: You may need to do some formatting

In the future, never listen to events within an event

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