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

253
Vistas
Why is my interaction collector not collecting? (discord.js)

I am a beginner coder in javascript and especially discord.js After wrapping my head around the discord.js guide, I still cannot get the collector to work.

client.on('interactionCreate', interaction => {
  if (!interaction.isButton()) return;
  const filter = i => i.customId === '1' || i.customId === "2";
  const collectchannel = interaction.channel;
  const collector = collectchannel.createMessageComponentCollector( filter, { time: 10000 });

  collector.on('collect', i => {
    if (i.customId === '1') {
      client.commands.get('help').execute(interaction, 1, Discord);
    } else if (i.customId === '2') {
      client.commands.get('help').execute(interaction, 2, Discord);
    }
  });

  collector.on('end', collected => {
    console.log(`Collected ${collected.size} interactions.`);
  });
});

When I press my button, the collect function doesn't do anything. I tried placing a console.log("test") but it doesn't fire. However, the collector.on('end', collected => { does in fact fire. This may be because I'm not a good coder. If you can, please help!

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You have a MessageComponentCollector inside an event handler for the interactionCreate event, which, in this circumstance, is probably not what you want.

Here's what's happening:

  1. You click the button

  2. Your eventCreate handler fires, checks if it's a button being clicked and starts the MessageComponentCollector

  3. The MessageComponentCollector waits for a button click, and doesn't fire yet because one has already happened (the one that fired your interactionCreate handler in the first place)

  4. Whenever you click the button again, the collector fires, but the interactionCreate handler does too, and you go back to #2, starting another collector


What you probably want is to handle your button clicks without a collector:

client.on('interactionCreate', interaction => {
    if (!interaction.isButton()) return;
    if (i.customId === '1') {
        client.commands.get('help').execute(interaction, 1, Discord);
    } else if (i.customId === '2') {
        client.commands.get('help').execute(interaction, 2, Discord);
    }
});
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