Discord.js 机器人错误,重复消息似乎不知从何而来

Discord.js bot error with repeated message that seemingly comes from nowhere

我遇到了一个问题,当我尝试与某人进行 1v1 时,它继续说“看起来你正在尝试 1v1 的用户是被动的!”

这是使用最新版本的 quick db 和 discord js。

我猜这只是我在输入内容时犯的一个愚蠢的错误。如果是这样,请告诉我!

这是我的1v1请求代码:

const db = require("quick.db");
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const { MessageEmbed } = require('discord.js')
const talkedRecently = new Set();

module.exports = {
  name: '1v1request',
  description: 'request someone to have a 1v1 ',
  execute(message, args, client) {

    if (talkedRecently.has(message.author.id)) {
      message.reply("Wait 1 day before being able to use this command again.");
    } else {

      const userto1v1 = message.mentions.users.first()

      if (!userto1v1) {
        message.channel.send('Make sure to specify a user!')
      } else {

        let userto1v1passive = db.get(`passive_${message.guild.id}_${userto1v1.id}`)

        if (userto1v1passive = 1) {

          message.channel.send("Looks like the user you are trying to 1v1 is passive!")

        } else {

          let amipassive = db.get(`passive_${message.guld.id}_${message.author.id}`)

          if (amipassive = 1) {

            message.channel.send("You are on passive!")

          } else {

            let trophies = db.get(`trophies_${message.guild.id}_${message.author.id}`)

            let trophies1 = db.get(`trophies_${message.guild.id}_${userto1v1.id}`)

            if (trophies < trophies1) {

              let trophiestobelost = (trophies1 - trophies) + 10

              client.channels.cache.get('944400414642688000').send(`**New 1v1 Request** - ${message.author} wishes to 1v1 ${userto1v1}! ${userto1v1} has 2 days to respond before they lose ${trophiestobelost} trophies!`);
              talkedRecently.add(message.author.id);
              setTimeout(() => {
                talkedRecently.delete(message.author.id);
              }, 86400000);

            } else {
              message.channel.send("You can't 1v1 someone with less or equal trophies than you!")
            }

          }
        }
      }
    }
  }
}

这是我的被动命令代码。

const db = require("quick.db");
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const { MessageEmbed } = require('discord.js')
const talkedRecently = new Set();

module.exports = {
  name: 'passive',
  description: 'turn on passive',
  execute(message, args, client) {

    if (talkedRecently.has(message.author.id)) {
      message.reply("Wait 2 days before being able to use this command again.");
    } else {

      let filter = m => m.author.id === message.author.id
      message.channel.send(`Would you like to enable or disable passive? \`ENABLE\` / \`DISABLE\``).then(() => {
        message.channel.awaitMessages(filter, {
          max: 1,
          time: 30000,
          errors: ['time']
        })
          .then(message => {
            message = message.first()
            if (message.content.toUpperCase() == 'ENABLE' || message.content.toUpperCase() == 'E') {

              db.set(`passive_${message.guild.id}_${message.author.id}`, 1)
              message.channel.send('Passive Enabled. Disabling passive will let you re-enable passive in 2 days. Passive will be automatically removed after 2 days.')

              setTimeout(() => {
                db.set(`passive_${message.guild.id}_${message.author.id}`, 0)
              }, 172800000);

            } else if (message.content.toUpperCase() == 'DISABLE' || message.content.toUpperCase() == 'D') {

              db.set(`passive_${message.guild.id}_${message.author.id}`, 0)

              message.channel.send('Succesfully disabled. You can use this command again in 2 days.')

              talkedRecently.add(message.author.id);
              setTimeout(() => {
                talkedRecently.delete(message.author.id);
              }, 172800000);

            } else {
              message.channel.send(`Invalid Response.`)
            }
          })
          .catch(collected => {
            message.channel.send('Timeout. Did not answer in time.');
          });
      })
    }

  }
}

您使用了错误的运算符。您需要使用 == 而不是 =。阅读有关这些运算符的更多信息 here。您的固定代码如下所示:

const db = require('quick.db');
const Discord = require('discord.js');
const client = new Discord.Client();
const fs = require('fs');
const { MessageEmbed } = require('discord.js');
const talkedRecently = new Set();

module.exports = {
    name: '1v1request',
    description: 'request someone to have a 1v1 ',
    execute(message, args, client) {
        if (talkedRecently.has(message.author.id)) {
            message.reply('Wait 1 day before being able to use this command again.');
        } else {
            const userto1v1 = message.mentions.users.first();

            if (!userto1v1) {
                message.channel.send('Make sure to specify a user!');
            } else {
                let userto1v1passive = db.get(`passive_${message.guild.id}_${userto1v1.id}`);

                if (userto1v1passive == 1) {
                    message.channel.send('Looks like the user you are trying to 1v1 is passive!');
                } else {
                    let amipassive = db.get(`passive_${message.guld.id}_${message.author.id}`);

                    if (amipassive == 1) {
                        message.channel.send('You are on passive!');
                    } else {
                        let trophies = db.get(`trophies_${message.guild.id}_${message.author.id}`);
                        let trophies1 = db.get(`trophies_${message.guild.id}_${userto1v1.id}`);

                        if (trophies < trophies1) {
                            let trophiestobelost = (trophies1 - trophies) + 10;
                            client.channels.cache.get('944400414642688000').send(`**New 1v1 Request** - ${message.author} wishes to 1v1 ${userto1v1}! ${userto1v1} has 2 days to respond before they lose ${trophiestobelost} trophies!`);
                            talkedRecently.add(message.author.id);
                            setTimeout(() => {
                                talkedRecently.delete(message.author.id);
                            }, 86400000);
                        } else {
                            message.channel.send('You can\'t 1v1 someone with less or equal trophies than you!');
                        }
                    }
                }
            }
        }
    }
}

希望对您有所帮助!