Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

164
Views
My bot is collecting it's own message (infinite loop) and spamming an specific line

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.

            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('` `')}\``);
                }
            }
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

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:

const collector = message.channel.createMessageCollector({ filter, max: 1 });
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!