Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

169
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda