簡體   English   中英

Discord.js forms

[英]Discord.js forms

我正在嘗試制作 forms 但對我來說效果不佳。 超時不起作用,我需要輸入兩次命令才能工作我不知道為什么

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);
          }
        }
      });
      
      
   
    },
};

從那里刪除messageCreate事件:

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);
          }
        }

注意:您可能需要進行一些格式化

將來,永遠不要在事件中監聽事件

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM