javascript - 我的不和谐机器人不会停止向我的命令发送垃圾邮件
问题描述
我向我的机器人添加了一个//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(
"` `"
)}\``
);
},
};
解决方案
超级容易修复!问题是您正在创建一个消息收集器TextChannel
然后发送您的消息,然后用户想要选择哪个位置,您只需将收集器移动到Message
对象而不是TextChannel
在发送消息之后。
推荐阅读
- node-modules - Angular v9 应用程序 [appendTo]="'body'" 中的 ng-select 不起作用
- java - 不要把位置当作固定的;仅立即使用并调用 `holder.getAdapterPosition()` 稍后查找
- python - 未找到模块错误 - 未找到 Pandas 模块
- python - 将 lambda 日志发送到特定日志组
- asp.net-web-api - 没有使用 Xunit 将记录保存到数据库中
- java - 不兼容的类型:java.lang.Class
无法转换为 - python - Python数据标签问题
- sql - 如何在 Sql Server 中将本地(est)列时区转换为 UTC 时区
- python - 如何使用递归python获取列表中的最大奇数?
- python - 如何在 ICICI 开发人员 API 中获取 URN