messageCreate isn't firing
I'm not getting messageCreate triggers when a message is sent in a chat channel.
To cover items from similar questions:
- I've triple-checked my intents (see below)
- I've got the "partials" thing in the code
- The bot is in the server (/commands work)
- The bot has access to all (one) channels
- Perms are properly set in the bot portal
Relevant Code:
The log from the
ClientReady
event is seen as expected, but the log from MessageCreate
never shows up at all.
Unless I'm totally understanding things, I should see that log every time someone writes something in the server where the bot is present, right?17 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!If you aren't getting any errors, try to place
console.log
checkpoints throughout your code to find out where execution stops.
- Once you do, log relevant values and if-conditions
- More sophisticated debugging methods are breakpoints and runtime inspections: learn moreIn the ready event, can you log
discord_client.channels.cache.get(<"channel_id">).viewable
?Looks like that narrows the problem...
I added:
And it tells me the bot has
0
cached channels.
Now the question is why...
(Incidentally, viewable
doesn't appear to be a property of channels.)Itβs a property of guild channels
You would need to cast or use the type guard
Gotcha.
In any case, there's nothing in the collection there.
I've double checked the perms and they look right to me.
Any thoughts on what's missing?
Can you check the guilds cache?
Sure thing π
It also reports being in
0
guilds.
(or there are zero in the cache at least - not sure if that means what I expect it to)And this is being logged in the ready event?
Yup:
Sounds like the part about the bot being in the server isn't true - you may have added the slash commands, or the slash commands are user installed, with the bot scope being enabled for that server
I... think that makes sense, but I'm not entirely sure I actually understand π
In fact, I'm fully sure I don't completely understand...
Can you throw that at me in different words and/or speculate about how that happens and how to fix it?
I have verified that the /commands are in fact talking to this specific server and back by checking the server logs and changing the message sent back in response to a simple "ping" even to something unique.
Slash commands use (or can use) a completely different system to adding the bot user to a server
The user is required for the guild (and its channels) to be in cache, and for regular events like messageCreate to be received and processed
If you only add its slash commands to the guild it will only receive and process interactionCreate events
That makes sense, thanks.
Now I'm trying to figure out how to google that problem considering it contains almost no unique search terms π
Its based on the scopes you defined when you add a bot to a server
"bot" is the bot user, "applications.commands" is the slash commands
So try re-adding it first with those scopes
You can use the URL generator in the dev portal to create an invite link with the necessary scopes.
Thanks much - this was in fact the issue, and easily fixed with your guidance. π
Much appreciated to all who helped! β₯οΈ
For posterity and anyone coming along later with this problem, we needed to go into the bot's setup on https://discord.com/developers/applications, to the
Installation
section, add bot
to the Guild Install
Scopes
then add the appropriate permissions from the dropdown, then re-add the bot to the server and approve all its new perms.
It was non-obvious that adding bot
would expand into a bunch more options, and we thought we had everything we needed with our other perms.