Message listener only on certain channels?

Hey there! So I have this:
module.exports = {
name: Events.MessageCreate,
async execute(message)
{
message.fetch()
.then(console.log)
.catch(console.error);
}
};
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.
8 Replies
d.js toolkit
d.js toolkit7mo 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
inkihh
inkihhOP7mo ago
$ npm list discord.js
[email protected] /var/www/trivia/bot
$ npm list discord.js
[email protected] /var/www/trivia/bot
$ node -v
v20.12.2
$ node -v
v20.12.2
chewie
chewie7mo ago
There is no extra method. You already mentioned the correct way in your question. Also fetching the message in that event isn't necessary.
inkihh
inkihhOP7mo ago
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
chewie
chewie7mo ago
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.
inkihh
inkihhOP7mo ago
well but with channel.createMessageCollector() I would save a lot of overhead, no? in terms of cpu on the backend
chewie
chewie7mo ago
that listens to the messageCreate event internally as well, there won't be a difference.
inkihh
inkihhOP7mo ago
oh ok thank you!
Want results from more Discord servers?
Add your server