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

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

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 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