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.
I am using discord.js@14.21.0 and node v24.4.0
20 Replies
Just to confirm: Your bot can view the channel?
Yes, it has admin privileges as well and I have a different command that has it send messages in that channel.
And you are sending that message within 5 seconds?
Yes, I set those on purpose for the sake of testing.
FWIW your code works on my machine, so it's not that
if you listen to the messageCreate event, does that fire
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?
Listen to the messageCreate event to see if that fires
What I meant by elaborating is how would I do that? I don't see a messageCreate event in the documentation.
How do I go about using this correctly? And what would it help with in my case?
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
To check if that event fires
If it does, the issue is with your collector
If it doesnt, its something else
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.
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
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.
you should not even need to create a client there
but good to know you found the issue
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
The thread owner has marked this issue as solved.