首页 > 解决方案 > 我的不和谐机器人不会停止向我的命令发送垃圾邮件

问题描述

我向我的机器人添加了一个//search命令。但是当我尝试运行它时,它给了我在哪里搜索的选项,但过了一会儿,它开始发送垃圾邮件,每次我输入频道时,它也会响应。我什至还没有回答这个问题,它立即开始回复并给我硬币。有没有办法解决这个问题?我已经多次扫描代码,没有发现错别字或错误;事实上,登录我的控制台也没有错误。

我的问题截图

如果需要代码,请在此处:

const profileModel = require("../models/profileSchema");

module.exports = {
  name: "search",
  aliases: [],
  permissions: [],
  cooldowns: 30,
  description: "Search for some coin!",
  async execute(message, args, cmd, client, Discord, profileData) {
    const locations = [
      "Dragonspine",
      "Windrise",
      "Qingyun Peak",
      "Mt. Hulao",
      "Mondstadt City",
      "Springvale",
      "Kamisato Estate",
      "Guyun Stone Forest",
      "Fort Mumei",
      "Watatsumi Island",
    ];

    const chosenLocations = locations
      .sort(() => Math.random() - Math.random())
      .slice(0, 3);

    const filter = ({ author, content }) =>
      message.author == author &&
      chosenLocations.some(
        (location) => location.toLowerCase() == content.toLowerCase()
      );

    const collector = message.channel.createMessageCollector(filter, {
      max: 1,
      time: 30000,
    });

    const earnings = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;

    collector.on("collect", async (m) => {
      message.channel.send(`You found ${earnings} primogems !`);

      await profileModel.findOneAndUpdate(
        {
          userID: message.author.id,
        },
        {
          $inc: {
            primogems: earnings,
          },
        }
      );
    });

    collector.on("end", (collected, reason) => {
      if (reason == "time") {
        message.channel.send("You ran out of time!");
      }
    });

    message.channel.send(
      `<@${
        message.author.id
      }> **Which location would you like to search?\n** Type the location in this channel\n \`${chosenLocations.join(
        "` `"
      )}\``
    );
  },
};

标签: javascriptnode.jsdiscord.js

解决方案


超级容易修复!问题是您正在创建一个消息收集器TextChannel然后发送您的消息,然后用户想要选择哪个位置,您只需将收集器移动到Message对象而不是TextChannel 发送消息之后。


推荐阅读