如何修复Discord机器人发送多个响应?

时间:2020-08-03 02:11:57

标签: node.js discord.js

因此,您应该输入!apply,该命令应该在收件箱中向author.id发送一条私人消息,并向其询问特定问题的列表。我遇到了一个问题,它同时向用户发送多个问题。我对discord.js并不了解,所以如果结构不好,请原谅我。如果您好奇,这是一个应用程序机器人。

Running into my command prompt sending this 
Apply begin for authorId 358036749055819779
Apply begin for authorId 358036749055819779
Apply begin for authorId 358036749055819779
const Discord = require("discord.js");
module.exports.run = async (bot, message, args) => {
  message.delete({ timeout: 10000 });




  let userApplications = {}
    bot.on("message", function(message) { ///NEED T


  if (message.author.equals(bot.user)) return;

  let authorId = message.author.id;


      console.log(`Apply begin for authorId ${authorId}`)= { "step" : 1};
      // User is not already in a registration process
      if (!(authorId in userApplications)) {
          userApplications[authorId] = { "step" : 1}

          message.author.send("```We need to ask some questions so  we can know a litte bit about yourself```");
          message.author.send("```What is your light level and the total amount of hours you have played destiny?``` https://wastedondestiny.com/");
      }

  else {

      if (message.channel.type === "dm" && authorId in userApplications) {
          let authorApplication = userApplications[authorId];

          if (authorApplication.step == 1 ) {
              authorApplication.answer1 = message.content;
              message.author.send("```Whats is your timezone?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 2) {
              authorApplication.answer2 = message.content;
              message.author.send("```How many days of the week do you play destiny?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 3) {
              authorApplication.answer3 = message.content;
              message.author.send("```What raids have you completed and how many times?``` https://raid.report/");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 4) {
              authorApplication.answer4 = message.content;
              message.author.send("```Do you belive in helping others even if you get nothing in return?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 5) {
              authorApplication.answer5 = message.content;
              message.author.send("```What is your reason for wanting to join FearTheWise?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 6) {
              authorApplication.answer6 = message.content;
              message.author.send("```What is your PSN?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 7) {
              authorApplication.answer7 = message.content;
              message.author.send("```Are you over 18 years of age?```");
              authorApplication.step ++;
          }
          else if (authorApplication.step == 8) {
              authorApplication.answer8 = message.content;
              message.author.send("```Thanks for your registration. Type !apply to register again```");


              let embed = new Discord.MessageEmbed()
                .setTitle('<:fearthewise:637422744610537492>-------Clan Application-------<:fearthewise:637422744610537492>')
                .setColor('#ffd700')
                .setThumbnail("https://i.imgur.com/eCYcee3.png")
                .addFields({name:'What is your light level and the total amount of hours you have played destiny? https://wastedondestiny.com/ ', value: `${authorApplication.answer1}`},)

                .addFields({name: 'Whats is your timezone? ', value: `${authorApplication.answer2}`},)

                .addFields({name: 'How many days of the week do you play destiny?', value: `${authorApplication.answer3}`},)

                .addFields({name: 'What raids have you completed and how many times? https://raid.report/', value: `${authorApplication.answer4}`},)

                .addFields({name: 'Do you belive in helping others even if you get nothing in return?', value: `${authorApplication.answer5}`},)

                .addFields({name: 'What is your reason for wanting to join FearTheWise?', value: `${authorApplication.answer6}`},)

                .addFields({name: 'What is your PSN?', value: `${authorApplication.answer7}`},)

                .addFields({name: 'Are you over 18 years of age?', value: `${authorApplication.answer8}`},)

                .addField("Applicant Username", `${message.author.username}#${message.author.discriminator}`)

                .setFooter("Bot created by James (Rock)₇₇₇",);





              //before deleting, you can send the answers to a specific channel by ID
              bot.channels.cache.get("616852008837709844")









            .send(embed).then(async msg => {
                await msg.react('?');
                await msg.react('?');
                await msg.react('?');
                await msg.react('?️');

                const threshold = 6;

    async function stop(result) {
      collector.stop();

      const newEmbed = new Discord.MessageEmbed(msg.embeds[0]);

      newEmbed.title = newEmbed.title + ' [CLOSED]';
      newEmbed.fields[0] = { name: 'Status', value: 'Voting is now closed.\n' + result };
      newEmbed.setThumbnail('attachment://thumbnail.png');
      await msg.edit(newEmbed);

      msg.reactions.removeAll();
    }

    async function update() {
      const newEmbed = new Discord.MessageEmbed(embed);

      const userYes = (votes['?'].size === 0)? '-' : [...votes['?']];
      const userNo = (votes['?'].size === 0)? '-' : [...votes['?']];
      const userUnsure = (votes['?'].size === 0)? '-' : [...votes['?']];

      newEmbed.addFields(
        { name: `Votes Yes (${votes['?'].size}/${threshold})`, value: userYes, inline: true },
        { name: `Votes No (${votes['?'].size}/${threshold})`, value: userNo, inline: true },
        { name: 'Vote unsure', value: userUnsure, inline: true }
      );

      await msg.edit(newEmbed);

      if (votes['?'].size >= threshold) {
        await stop('This answer is good enough to get accepted and an upvote.');
        // do something
      } else if (votes['?'].size >= threshold) {
        await stop('This answer is not good enough to get accepted and an upvote.');
        // do something
      }
    }

    const votes = {
      '?': new Set(),
      '?': new Set(),
      '?': new Set(),
      '?️': new Set()
    };

    update();

    const collector = msg.createReactionCollector((reaction, user) => !user.bot , { dispose: true });

    collector.on('collect', async (reaction, user) => {
      if (['?', '?', '?', '?️'].includes(reaction.emoji.name)) {
        const userReactions = msg.reactions.cache.filter(reaction => reaction.users.cache.has(user.id));

        for (const userReaction of userReactions.values()) {
          if (userReaction.emoji.name !== reaction.emoji.name || reaction.emoji.name === '?️') {
            userReaction.users.remove(user.id);
            votes[userReaction.emoji.name].delete(user);
          }
        }

        votes[reaction.emoji.name].add(user);
      } else {
        reaction.remove();
      }

      update();
    });

    collector.on('remove', (reaction, user) => {
      votes[reaction.emoji.name].delete(user);

      update();
    });
  });


              delete userApplications[authorId];
          }
      }
  }
});


}


module.exports.help = {
    name: "apply"
}

1 个答案:

答案 0 :(得分:0)

尝试changing your bot token。您的漫游器可能正在运行多次,并且所有实例都在响应。如果更改令牌后仍然发生这种情况,请尝试在终端中使用client.destroy()或cmd + Z(杀死脚本)。

如果以上方法均无济于事,请重新启动计算机。