我的机器人正在收集它自己的消息(无限循环)并向特定行发送垃圾邮件
My bot is collecting it's own message (infinite loop) and spamming an specific line
机器人向 (`You Found ${earnings} Coins!`);
发送垃圾邮件
我认为它正在收集自己的消息(无限循环)
我向我的一些朋友询问了这个问题,他们说了同样的话:“机器人正在收集它自己的消息,删除收集器”。但我不知道如何更换收集器。
const profileModel = require("../models/profileSchema");
module.exports = {
name: "search",
aliases: [],
permissions: [],
description: "Search for some coin!",
async execute(message, args, cmd, client, Discord, profileData) {
const locations = [
"car",
"bathroom",
"park",
"truck",
"pocket",
"computer"
];
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});
const earnings = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;
collector.on('collect', async (m) => {
if(message.author.bot) return;
message.channel.send(`You Found ${earnings} Coins!`);
await profileModel.findOneAndUpdate(
{
userID: message.author.id,
},
{
$inc: {
PDMcoins: earnings,
},
}
);
});
message.channel.send(`<@${message.author.id}> which location would you like to search?\n type it in this channel\n \`${chosenLocations.join('` `')}\``);
}
}
在 discord.js v13 中所有 Collector
相关的 类 和方法(例如 .createMessageCollector()
或 .awaitMessages()
)采用单个 object 参数还包括 filter
。所以,您的收藏家应该是这样的:
const collector = message.channel.createMessageCollector({ filter, max: 1 });
机器人向 (`You Found ${earnings} Coins!`);
发送垃圾邮件
我认为它正在收集自己的消息(无限循环)
我向我的一些朋友询问了这个问题,他们说了同样的话:“机器人正在收集它自己的消息,删除收集器”。但我不知道如何更换收集器。
const profileModel = require("../models/profileSchema");
module.exports = {
name: "search",
aliases: [],
permissions: [],
description: "Search for some coin!",
async execute(message, args, cmd, client, Discord, profileData) {
const locations = [
"car",
"bathroom",
"park",
"truck",
"pocket",
"computer"
];
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});
const earnings = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;
collector.on('collect', async (m) => {
if(message.author.bot) return;
message.channel.send(`You Found ${earnings} Coins!`);
await profileModel.findOneAndUpdate(
{
userID: message.author.id,
},
{
$inc: {
PDMcoins: earnings,
},
}
);
});
message.channel.send(`<@${message.author.id}> which location would you like to search?\n type it in this channel\n \`${chosenLocations.join('` `')}\``);
}
}
在 discord.js v13 中所有 Collector
相关的 类 和方法(例如 .createMessageCollector()
或 .awaitMessages()
)采用单个 object 参数还包括 filter
。所以,您的收藏家应该是这样的:
const collector = message.channel.createMessageCollector({ filter, max: 1 });