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

117
Vistas
Discord.js messageCollector won't collect messages

I'm trying to create a discord bot, which can create a thread and after running a command, collect the messages. There is my code:

require('dotenv').config();

const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
    data: new SlashCommandBuilder()
        .setName('start')
        .setDescription('Start the story'),
    async execute(interaction, client) {
        
        ...

        const filter = () => true;

        client.collectors.set(`collector${channel.id}`, channel.createMessageCollector({ filter, time: 30000, max: 1000 }));

        const collector = client.collectors.get(`collector${channel.id}`);

        collector.on('collect', m => {
            console.log(`Collected ${m.content}`);
        });

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

        ...
    },
};

My first idea was that after the command is ran, the collector will be removed from memory, that's why I gave the client a property, a collection named collectors, but the collect event still won't run and the end event will only run after the thread is deleted, or when the time limit ended, but then it logs "Collected 0 items" even though there were messages sent.

Tried creating it in a function in index.js but that didn't help either.

Update: added () => true as filter, changed nothing...

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

0

I solved the issue by adding GatewayIntentBits.GuildMessages and GatewayIntentBits.MessageContent to the client's intents in index.js, so the line where I create the client object now looks like this:

const client = new Client({ intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMessages, GatewayIntentBits.MessageContent] });
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