Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

168
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda