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`);
});
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`);
});
},
};
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`);
});
},
};
2 Replies
d.js toolkit
d.js toolkit2mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
dainis
dainisOP2mo ago
Started refreshing 3 application (/) commands.
Successfully reloaded 3 application (/) commands.
4 | name: Events.ClientReady,
5 | once: false,
6 | execute(client) {
7 | const channel = client.channels.fetch("1221529963761500160");
8 |
9 | const collector = channel.createMessageCollector({
^
TypeError: client.channels.fetch("1221529963761500160").createMessageCollector is not a function. (In 'client.channels.fetch("1221529963761500160").createMessageCollector({
time: 15000
})', 'client.channels.fetch("1221529963761500160").createMessageCollector' is undefined)
at execute (/home/dainis/bot/events/sim.js:9:31)
at /home/dainis/bot/index.ts:41:46
at emit2 (node:events:79:45)
at triggerClientReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:381:17)
at checkShardsReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:364:10)
at /home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:194:16
at emit (node:events:48:48)
at checkReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:184:12)
at gotGuild (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:158:10)
at /home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:234:15

Bun v1.1.31 (Linux x64)
Started refreshing 3 application (/) commands.
Successfully reloaded 3 application (/) commands.
4 | name: Events.ClientReady,
5 | once: false,
6 | execute(client) {
7 | const channel = client.channels.fetch("1221529963761500160");
8 |
9 | const collector = channel.createMessageCollector({
^
TypeError: client.channels.fetch("1221529963761500160").createMessageCollector is not a function. (In 'client.channels.fetch("1221529963761500160").createMessageCollector({
time: 15000
})', 'client.channels.fetch("1221529963761500160").createMessageCollector' is undefined)
at execute (/home/dainis/bot/events/sim.js:9:31)
at /home/dainis/bot/index.ts:41:46
at emit2 (node:events:79:45)
at triggerClientReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:381:17)
at checkShardsReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:364:10)
at /home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:194:16
at emit (node:events:48:48)
at checkReady (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:184:12)
at gotGuild (/home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketShard.js:158:10)
at /home/dainis/bot/node_modules/discord.js/src/client/websocket/WebSocketManager.js:234:15

Bun v1.1.31 (Linux x64)
No, I wanted for it to get every message in all channels and log them in the console, but my end goal for all this turned out to be impossible to achieve seemingly so I'll mark this thread as closed
Want results from more Discord servers?
Add your server