Collections not collecting channel messages

I am using the code sample code from basic message collector, but am struggling to get it to work at all. It seems no matter what I try, it always collects 0. I have added the following to my client: - GatewayIntentBits.Guilds, - GatewayIntentBits.GuildMessages, - GatewayIntentBits.MessageContent I have Message Content Intent turned on in discord developer as well. I have it running in a slash command. After I execute the command, I then type discord, but in the console, it just shows 0. No amount of searching (last few hours) has helped at all. I know I am missing something, but this isn't the first time I am scouring d.js documentation for more context than it gives when it comes to examples. The code I have inside of the slash command I made just for testing.
await interaction.reply({
content: `Executing command`,
withResponse: true,
});
const collectorFilter = (m: Message) => m.content.includes("discord");
const channel = interaction.channel as TextChannel;
const collector = channel.createMessageCollector({
filter: collectorFilter,
time: 5_000,
max: 1,
});

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

collector.on("end", (collected) => {
console.log(`Collected ${collected.size} items`);
});
await interaction.reply({
content: `Executing command`,
withResponse: true,
});
const collectorFilter = (m: Message) => m.content.includes("discord");
const channel = interaction.channel as TextChannel;
const collector = channel.createMessageCollector({
filter: collectorFilter,
time: 5_000,
max: 1,
});

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

collector.on("end", (collected) => {
console.log(`Collected ${collected.size} items`);
});
I am using discord.js@14.21.0 and node v24.4.0
20 Replies
d.js toolkit
d.js toolkit5mo ago
edocsil
edocsil5mo ago
Just to confirm: Your bot can view the channel?
gnp
gnpOP5mo ago
Yes, it has admin privileges as well and I have a different command that has it send messages in that channel.
treble/luna
treble/luna5mo ago
And you are sending that message within 5 seconds?
gnp
gnpOP5mo ago
Yes, I set those on purpose for the sake of testing.
edocsil
edocsil5mo ago
FWIW your code works on my machine, so it's not that
treble/luna
treble/luna5mo ago
if you listen to the messageCreate event, does that fire
gnp
gnpOP5mo ago
Hmm, then that makes me think there's something with the bot, but if it has admin privileges and Message Content Intent, then I guess it's something else I am not seeing. Can you elaborate?
treble/luna
treble/luna5mo ago
Listen to the messageCreate event to see if that fires
gnp
gnpOP5mo ago
What I meant by elaborating is how would I do that? I don't see a messageCreate event in the documentation.
d.js docs
d.js docs5mo ago
:event: (event) Client#messageCreate discord.js@14.21.0 Emitted whenever a message is created.
gnp
gnpOP5mo ago
How do I go about using this correctly? And what would it help with in my case?
Samtino
Samtino5mo ago
The messageCreate event is the same endpoint that createMessageCollector listens to, just you can keep it open all the time...they're checking if your bot is receiving ANY messageCreate events
treble/luna
treble/luna5mo ago
To check if that event fires If it does, the issue is with your collector If it doesnt, its something else
gnp
gnpOP5mo ago
I guess it's the implementation of this messageCreate that I am unfamiliar with. Like, how to create it. I am assuming it's similar to interactionCreate? The guide as far as I can tell, goes over interactionCreate, but I haven't come across messageCreate.
treble/luna
treble/luna5mo ago
its just another event you listen like it just like you would listen to any other event on the client and it'll fire with a Message
gnp
gnpOP5mo ago
Welp, found the problem. I was adding intents to the client in interactionCreate file and not the index one, which I just realized was the client I needed to add the intents to. Which makes sense now. Just didn't catch that at first. Sorry for wasting everyone's time. It works as expected.
treble/luna
treble/luna5mo ago
you should not even need to create a client there but good to know you found the issue
gnp
gnpOP5mo ago
Well, I went by the documentation, but I agree with you. I'm just going to change that one and export the client from index into interactionCreate instead
d.js toolkit
d.js toolkit5mo ago
The thread owner has marked this issue as solved.

Did you find this page helpful?