【发布时间】:2021-09-09 10:31:13
【问题描述】:
我向我的机器人添加了//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(
"` `"
)}\``
);
},
};
【问题讨论】:
标签: javascript node.js discord.js