Message listener only on certain channels?
Hey there! So I have this:
This apparently listens to every channel the bot has access to. Can I restrict it to just one channel or some channels? I can probably check the channel id within the body of
execute(message)
but I wonder if there's a method that only listens to certain channels in the first place.8 Replies
- 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 OPThere is no extra method. You already mentioned the correct way in your question.
Also fetching the message in that event isn't necessary.
So if a bot is added to a Discord with dozens of channels, Events.MessageCreate would get all messages of the whole server? that seems like a huge overhead, if I only want to monitor the messages in one channel.
I remember in the old days you could only listen to one channel, but I can't remember how
You cant. That event emits every time the bot receives a message, doesn't matter which channel.
Always has been like that.
What you are probably referring to is using
channel.createMessageCollector()
, which only collects messages in that channel, but its basically the same as using the messageCreate event and checking the channel.well but with channel.createMessageCollector() I would save a lot of overhead, no?
in terms of cpu on the backend
that listens to the messageCreate event internally as well, there won't be a difference.
oh ok
thank you!