the bot spams the (`You Found ${earnings} Coins!`);
and I think it’s collecting it’s own messages (infinite loop)
I asked the problem from some of my friends and they said the same: “the bot is collecting it’s own messages, remove the collector”. but I don’t know how can I replace the collector.
JavaScript
x
49
49
1
const profileModel = require("../models/profileSchema");
2
3
module.exports = {
4
name: "search",
5
aliases: [],
6
permissions: [],
7
description: "Search for some coin!",
8
async execute(message, args, cmd, client, Discord, profileData) {
9
10
const locations = [
11
"car",
12
"bathroom",
13
"park",
14
"truck",
15
"pocket",
16
"computer"
17
];
18
19
const chosenLocations = locations.sort(() => Math.random() - Math.random()).slice(0, 3);
20
21
const filter = ({ author, content }) => message.author == author && chosenLocations.some((location) => location.toLowerCase() == content.toLowerCase());
22
23
const collector = message.channel.createMessageCollector(filter, { max: 1});
24
25
const earnings = Math.floor(Math.random() * (1000 - 100 + 1)) + 100;
26
27
28
collector.on('collect', async (m) => {
29
if(message.author.bot) return;
30
message.channel.send(`You Found ${earnings} Coins!`);
31
32
await profileModel.findOneAndUpdate(
33
{
34
userID: message.author.id,
35
},
36
{
37
$inc: {
38
PDMcoins: earnings,
39
},
40
}
41
);
42
});
43
44
45
46
message.channel.send(`<@${message.author.id}> which location would you like to search?n type it in this channeln `${chosenLocations.join('` `')}``);
47
}
48
}
49
Advertisement
Answer
In discord.js v13 all Collector
related classes and methods (e.g. .createMessageCollector()
or .awaitMessages()
) take a single object parameter which also includes the filter
. So, your collector should look like this:
JavaScript
1
2
1
const collector = message.channel.createMessageCollector({ filter, max: 1 });
2