Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

114
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!