#Message listener only on certain channels?

14 messages · Page 1 of 1 (latest)

wicked nymph
#

Hey there! So I have this:

module.exports = {
    name: Events.MessageCreate,
    async execute(message)
    {
        message.fetch()
        .then(console.log)
        .catch(console.error);
    }
};

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.

near questBOT
#
  • What's your exact discord.js npm list discord.js and node node -v version?
  • Not a discord.js issue? Check out #1081585952654360687.
  • 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
wicked nymph
#
$ node -v
v20.12.2
rapid oasis
#

There is no extra method. You already mentioned the correct way in your question.

#

Also fetching the message in that event isn't necessary.

wicked nymph
#

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

rapid oasis
#

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.

wicked nymph
#

well but with channel.createMessageCollector() I would save a lot of overhead, no?

#

in terms of cpu on the backend

rapid oasis
#

that listens to the messageCreate event internally as well, there won't be a difference.

wicked nymph
#

oh ok