A collector that collects messages from a predetermined channel

const collectorFilter = m => m.content.includes('discord');
const collector = interaction.channel.createMessageCollector({ filter: collectorFilter, time: 15_000 });

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

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


I used this code as a basis, however I had no idea how to make it work in a specific channel without the need of it being triggered by a slash command (I put it in the events folder aswell). Here's how far i've gone

const { Events } = require("discord.js");

module.exports = {
  name: Events.ClientReady,
  once: false,
  execute(client) {
    const channel = client.channels.fetch("1221529963761500160");

    const collector = channel.createMessageCollector({
      time: 15_000,
    });

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

    collector.on("end", (collected) => {
      console.log(`Collected ${collected.size} items`);
    });
  },
};
Was this page helpful?